Skip to content

Commit

Permalink
REBASE: Fixed markdown lint errors in ReadMe.md for FMMT
Browse files Browse the repository at this point in the history
  • Loading branch information
kenlautner committed May 9, 2023
1 parent 822d50e commit 65fc23d
Showing 1 changed file with 64 additions and 44 deletions.
108 changes: 64 additions & 44 deletions BaseTools/Source/Python/FMMT/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
# FMMT

## Overview
This FMMT tool is the python implementation of the edk2 FMMT tool which locates at https://github.com/tianocore/edk2-staging/tree/FceFmmt.

This FMMT tool is the python implementation of the edk2 FMMT tool which locates at <https://github.com/tianocore/edk2-staging/tree/FceFmmt>
This implementation has the same usage as the edk2 FMMT, but it's more readable and relaiable.

# FMMT User Guide
## FMMT User Guide

#### Last updated April 28, 2022
### Last updated April 28, 2022

Important Changes and Updates:

- Oct 13, 2021 Initial Draft of FMMT Python Tool
- Apr 28, 2022 Optimize functions & Command line

#### Note:
#### Note

- FMMT Python Tool keeps same function with origin FMMT C Tool. It is much easier to maintain and extend other functions.

#### Known issue:
#### Known issue

- Currently, FMMT Python tool does not support PEIM rebase feature, this feature will be added in future update.

# 1. Introduction
## 1. Introduction

## 1.1 Overview
### 1.1 Overview

The Firmware Device is a persistent physical repository that contains firmware code and/or data. The firmware code and/or data stored in Firmware Volumes. Detail layout of Firmware Volumes is described in ?Figure 1. The Firmware Volume Format?.
The Firmware Device is a persistent physical repository that contains firmware code and/or data. The firmware code
and/or data stored in Firmware Volumes. Detail layout of Firmware Volumes is described in ?Figure 1. The Firmware
Volume Format?.

![](Img/FirmwareVolumeFormat.png)
![ref](Img/FirmwareVolumeFormat.png)

? Figure 1. The Firmware Volume Format

In firmware development, binary file has its firmware layout following the Platform-Initialization Specification. Thus, operation on FV file / FFS file (Firmware File) is an efficient and convenient way for firmware function testing and developing. FMMT Python tool is used for firmware files operation.
In firmware development, binary file has its firmware layout following the Platform-Initialization Specification. Thus,
operation on FV file / FFS file (Firmware File) is an efficient and convenient way for firmware function testing and
developing. FMMT Python tool is used for firmware files operation.

## 1.2 Tool Capabilities
### 1.2 Tool Capabilities

The FMMT tool is capable of:

Expand All @@ -44,90 +50,102 @@ The FMMT tool is capable of:

- Delete an FFS in a FV file (both included in a FD file or not)

- Extract the FFS from a FV file (both included in a FD file or not)
- Extract the FFS from a FV file (both included in a FD file or not)

## 1.3 References
### 1.3 References

| Document |
| ------------------------------------------------ |
| UEFI Platform Initialization (PI) Specification |

# 2. FMMT Python Tool Usage
## 2. FMMT Python Tool Usage

## 2.1 Required Files
### 2.1 Required Files

### 2.1.1 Independent use
#### 2.1.1 Independent use

When independent use the FMMT Python Tool, the following files and settings are required:

- GuidTool executable files used for Decompress/Compress Firmware data.

- Environment variables path with GuidTool path setting.

### 2.1.2 Use with Build System
#### 2.1.2 Use with Build System

When use the FMMT Python Tool with Build System:

- If only use Edk2 based GuidTool, do not need other preparation.
- If only use Edk2 based GuidTool, do not need other preparation.

- If use other customized GuidTool, need prepare the config file with GuidTool info. The syntax for GuidTool definition shown as follow:
- If use other customized GuidTool, need prepare the config file with GuidTool info. The syntax for GuidTool definition
shown as follow:

***ToolsGuid ShortName Command***

-- Example: ***3d532050-5cda-4fd0-879e-0f7f630d5afb BROTLI BrotliCompress***

## 2.2 Syntax
### 2.2 Syntax

### 2.2.1 Syntax for Parse file
#### 2.2.1 Syntax for Parse file

***-v < Inputfile > < Outputfile > -l < LogFileType > -c < ConfigFilePath >***

- Parse *Inputfile*, show its firmware layout with log file. *Outputfile* is optional, if inputs, the *Inputfile* will be encapsulated into *Outputfile* following the parsed firmware layout. *"-l LogFileType"* is optional, it decides the format of log file which saves Binary layout. Currently supports: json, txt. More formats will be added in the future. *"-c ConfigFilePath "* is optional, target FmmtConf.ini file can be selected with this parameter. If not provided, default FmmtConf.ini file will be used.
- Parse *Inputfile*, show its firmware layout with log file. *Outputfile* is optional, if inputs, the *Inputfile* will
be encapsulated into *Outputfile* following the parsed firmware layout. *"-l LogFileType"* is optional, it decides the
format of log file which saves Binary layout. Currently supports: json, txt. More formats will be added in the future.
*"-c ConfigFilePath "* is optional, target FmmtConf.ini file can be selected with this parameter. If not provided,
default FmmtConf.ini file will be used.
- Ex: py -3 FMMT.py -v test.fd

### 2.2.2 Syntax for Add a new FFS
#### 2.2.2 Syntax for Add a new FFS

***-a < Inputfile > < TargetFvName/TargetFvGuid > < NewFfsFile > < Outputfile >***

- Add the *NewFfsFile* into *Inputfile*. *TargetFvName/TargetFvGuid* (Name or Guid) is the TargetFv which *NewFfsFile* will be added into.
- Add the *NewFfsFile* into *Inputfile*. *TargetFvName/TargetFvGuid* (Name or Guid) is the TargetFv which *NewFfsFile*
will be added into.
- Ex: py -3 FMMT.py -a Ovmf.fd 6938079b-b503-4e3d-9d24-b28337a25806 NewAdd.ffs output.fd

### 2.2.3 Syntax for Delete an FFS
#### 2.2.3 Syntax for Delete an FFS

***-d < Inputfile > < TargetFvName/TargetFvGuid > < TargetFfsName > < Outputfile >***

- Delete the Ffs from *Inputfile*. TargetFfsName (Guid) is the TargetFfs which will be deleted. *TargetFvName/TargetFvGuid* is optional, which is the parent of TargetFfs*.*
- Delete the Ffs from *Inputfile*. TargetFfsName (Guid) is the TargetFfs which will be deleted. *TargetFvName/TargetFvGuid*
is optional, which is the parent of TargetFfs*.*
- Ex: py -3 FMMT.py -d Ovmf.fd 6938079b-b503-4e3d-9d24-b28337a25806 S3Resume2Pei output.fd

### 2.2.4 Syntax for Replace an FFS
#### 2.2.4 Syntax for Replace an FFS

? ***-r < Inputfile > < TargetFvName/TargetFvGuid > < TargetFfsName > < NewFfsFile > < Outputfile >***

- Replace the Ffs with the NewFfsFile. TargetFfsName (Guid) is the TargetFfs which will be replaced. *TargetFvName/TargetFvGuid* is optional, which is the parent of TargetFfs*.*
- Replace the Ffs with the NewFfsFile. TargetFfsName (Guid) is the TargetFfs which will be replaced.
*TargetFvName/TargetFvGuid* is optional, which is the parent of TargetFfs*.*
- Ex: py -3 FMMT.py -r Ovmf.fd 6938079b-b503-4e3d-9d24-b28337a25806 S3Resume2Pei NewS3Resume2Pei.ffs output.fd

### 2.2.5 Syntax for Extract an FFS
#### 2.2.5 Syntax for Extract an FFS

***-e < Inputfile > < TargetFvName/TargetFvGuid > < TargetFfsName > < Outputfile >***

- Extract the Ffs from the Inputfile. TargetFfsName (Guid) is the TargetFfs which will be extracted. *TargetFvName/TargetFvGuid* is optional, which is the parent of TargetFfs*.*
- Extract the Ffs from the Inputfile. TargetFfsName (Guid) is the TargetFfs which will be extracted.
*TargetFvName/TargetFvGuid* is optional, which is the parent of TargetFfs*.*
- Ex: py -3 FMMT.py -e Ovmf.fd 6938079b-b503-4e3d-9d24-b28337a25806 S3Resume2Pei output.fd

# 3. FMMT Python Tool Design
## 3. FMMT Python Tool Design

FMMT Python Tool uses the NodeTree saves whole Firmware layout. Each Node have its Data field, which saves the FirmwareClass(FD/FV/FFS/SECTION/BINARY) Data. All the parse/add/delete/replace/extract operations are based on the NodeTree (adjusting the layout and data).
FMMT Python Tool uses the NodeTree saves whole Firmware layout. Each Node have its Data field, which saves the
FirmwareClass(FD/FV/FFS/SECTION/BINARY) Data. All the parse/add/delete/replace/extract operations are based on the
NodeTree (adjusting the layout and data).

## 3.1 NodeTree
### 3.1 NodeTree

A whole NodeTree saves all the Firmware info.

- Parent & Child relationship figured out the Firmware layout.

- Each Node have several fields. ?Data? field saves an FirmwareClass instance which contains all the data info of the info.

### 3.1.1 NodeTree Format
#### 3.1.1 NodeTree Format

The NodeTree will be created with parse function. When parse a file, a Root Node will be initialized firstly. The Data split and Tree construction process is described with an FD file shown as ?Figure 2. The NodeTree format?:
The NodeTree will be created with parse function. When parse a file, a Root Node will be initialized firstly. The Data
split and Tree construction process is described with an FD file shown as ?Figure 2. The NodeTree format?:

- A Root Node is initialized.

Expand All @@ -139,19 +157,21 @@ The NodeTree will be created with parse function. When parse a file, a Root Node

- If some of Section includes other Sections, continue use the ?Section Data Size? as Section key to split each Section Data.

- After all Node created, the whole NodeTree saves all the info. (Can be used in other functions or print the whole firmware layout into log file)
- After all Node created, the whole NodeTree saves all the info. (Can be used in other functions or print the whole
firmware layout into log file)

![](Img/NodeTreeFormat.png)
![ref](Img/NodeTreeFormat.png)

? Figure 2. The NodeTree format

### 3.1.2 Node Factory and Product
#### 3.1.2 Node Factory and Product

As 3.1.1, Each Node is created by data split and recognition. To extend the NodeTree usage, Factory pattern is used in Node created process.
As 3.1.1, Each Node is created by data split and recognition. To extend the NodeTree usage, Factory pattern is used in
Node created process.

Each Node have its Factory to create Product and use Product ParserData function to deal with the data.

## 3.2 GuidTool
### 3.2 GuidTool

There are two ways to set the GuidTool. One from Config file, another from environment variables.

Expand All @@ -161,24 +181,24 @@ Current GuidTool first check if has Config file.

- Else get from environment variables.

### 3.2.1 Get from Config file
#### 3.2.1 Get from Config file

- Config file should in same folder with FMMT.py or the path in environment variables.

- Content should follow the format:

***ToolsGuid ShortName Command***

### 3.2.2 Get from Environment Variables
#### 3.2.2 Get from Environment Variables

- The GuidTool Command used must be set in environment variables.

### 3.2.3 Edk2 Based GuidTool
#### 3.2.3 Edk2 Based GuidTool

| ***Guid*** | ***ShortName*** | ***Command*** |
| ------------------------------------------ | --------------- | --------------------- |
| ***a31280ad-481e-41b6-95e8-127f4c984779*** | ***TIANO*** | ***TianoCompress*** |
| ***ee4e5898-3914-4259-9d6e-dc7bd79403cf*** | ***LZMA*** | ***LzmaCompress*** |
| ***fc1bcdb0-7d31-49aa-936a-a4600d9dd083*** | ***CRC32*** | ***GenCrc32*** |
| ***d42ae6bd-1352-4bfb-909a-ca72a6eae889*** | ***LZMAF86*** | ***LzmaF86Compress*** |
| ***3d532050-5cda-4fd0-879e-0f7f630d5afb*** | ***BROTLI*** | ***BrotliCompress*** |
| ***3d532050-5cda-4fd0-879e-0f7f630d5afb*** | ***BROTLI*** | ***BrotliCompress*** |

0 comments on commit 65fc23d

Please sign in to comment.