diff options
author | Chen, Christine <Yuwei.Chen@intel.com> | 2022-04-28 20:49:37 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2022-05-06 04:22:21 +0000 |
commit | a64b944942d828fe98e4843929662aad7f47bcca (patch) | |
tree | f712c0a1d049128788e81c6a0611891a16d98a2b /BaseTools/Source/Python/FirmwareStorageFormat/FvHeader.py | |
parent | 101f4c789221716585b972f2c2a22a85c078ef1d (diff) | |
download | edk2-a64b944942d828fe98e4843929662aad7f47bcca.tar.gz edk2-a64b944942d828fe98e4843929662aad7f47bcca.tar.bz2 edk2-a64b944942d828fe98e4843929662aad7f47bcca.zip |
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>
Diffstat (limited to 'BaseTools/Source/Python/FirmwareStorageFormat/FvHeader.py')
-rw-r--r-- | BaseTools/Source/Python/FirmwareStorageFormat/FvHeader.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/FirmwareStorageFormat/FvHeader.py b/BaseTools/Source/Python/FirmwareStorageFormat/FvHeader.py new file mode 100644 index 0000000000..078beda9e5 --- /dev/null +++ b/BaseTools/Source/Python/FirmwareStorageFormat/FvHeader.py @@ -0,0 +1,112 @@ +## @file
+# This file is used to define the FV Header C Struct.
+#
+# Copyright (c) 2021-, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+from ast import Str
+from struct import *
+from ctypes import *
+from FirmwareStorageFormat.Common import *
+
+class EFI_FV_BLOCK_MAP_ENTRY(Structure):
+ _pack_ = 1
+ _fields_ = [
+ ('NumBlocks', c_uint32),
+ ('Length', c_uint32),
+ ]
+
+
+class EFI_FIRMWARE_VOLUME_HEADER(Structure):
+ _fields_ = [
+ ('ZeroVector', ARRAY(c_uint8, 16)),
+ ('FileSystemGuid', GUID),
+ ('FvLength', c_uint64),
+ ('Signature', c_uint32),
+ ('Attributes', c_uint32),
+ ('HeaderLength', c_uint16),
+ ('Checksum', c_uint16),
+ ('ExtHeaderOffset', c_uint16),
+ ('Reserved', c_uint8),
+ ('Revision', c_uint8),
+ ('BlockMap', ARRAY(EFI_FV_BLOCK_MAP_ENTRY, 1)),
+ ]
+
+def Refine_FV_Header(nums):
+ class EFI_FIRMWARE_VOLUME_HEADER(Structure):
+ _fields_ = [
+ ('ZeroVector', ARRAY(c_uint8, 16)),
+ ('FileSystemGuid', GUID),
+ ('FvLength', c_uint64),
+ ('Signature', c_uint32),
+ ('Attributes', c_uint32),
+ ('HeaderLength', c_uint16),
+ ('Checksum', c_uint16),
+ ('ExtHeaderOffset', c_uint16),
+ ('Reserved', c_uint8),
+ ('Revision', c_uint8),
+ ('BlockMap', ARRAY(EFI_FV_BLOCK_MAP_ENTRY, nums)),
+ ]
+ return EFI_FIRMWARE_VOLUME_HEADER
+
+class EFI_FIRMWARE_VOLUME_EXT_HEADER(Structure):
+ _fields_ = [
+ ('FvName', GUID),
+ ('ExtHeaderSize', c_uint32)
+ ]
+
+class EFI_FIRMWARE_VOLUME_EXT_ENTRY(Structure):
+ _fields_ = [
+ ('ExtEntrySize', c_uint16),
+ ('ExtEntryType', c_uint16)
+ ]
+
+class EFI_FIRMWARE_VOLUME_EXT_ENTRY_OEM_TYPE_0(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('TypeMask', c_uint32)
+ ]
+
+class EFI_FIRMWARE_VOLUME_EXT_ENTRY_OEM_TYPE(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('TypeMask', c_uint32),
+ ('Types', ARRAY(GUID, 1))
+ ]
+
+def Refine_FV_EXT_ENTRY_OEM_TYPE_Header(nums: int) -> EFI_FIRMWARE_VOLUME_EXT_ENTRY_OEM_TYPE:
+ class EFI_FIRMWARE_VOLUME_EXT_ENTRY_OEM_TYPE(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('TypeMask', c_uint32),
+ ('Types', ARRAY(GUID, nums))
+ ]
+ return EFI_FIRMWARE_VOLUME_EXT_ENTRY_OEM_TYPE(Structure)
+
+class EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE_0(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('FormatType', GUID)
+ ]
+
+class EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('FormatType', GUID),
+ ('Data', ARRAY(c_uint8, 1))
+ ]
+
+def Refine_FV_EXT_ENTRY_GUID_TYPE_Header(nums: int) -> EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE:
+ class EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('FormatType', GUID),
+ ('Data', ARRAY(c_uint8, nums))
+ ]
+ return EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE(Structure)
+
+class EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE(Structure):
+ _fields_ = [
+ ('Hdr', EFI_FIRMWARE_VOLUME_EXT_ENTRY),
+ ('UsedSize', c_uint32)
+ ]
|