Re: [edk2-devel] [Patch V1 3/3] BaseTools: FMMT support ELF UPLD parser
Reviewed-by: Bob Feng -Original Message- From: Chen, Christine Sent: Tuesday, April 18, 2023 5:55 PM To: devel@edk2.groups.io Cc: Rebecca Cran ; Feng, Bob C ; Gao, Liming Subject: [Patch V1 3/3] 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 Cc: Bob Feng Cc: Liming Gao Signed-off-by: Yuwei Chen --- BaseTools/Source/Python/FMMT/FMMT.py | 2 ++ BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py | 36 +++- BaseTools/Source/Python/FMMT/core/BiosTree.py | 48 ++-- BaseTools/Source/Python/FMMT/core/BiosTreeNode.py | 56 +++- BaseTools/Source/Python/FMMT/core/FMMTParser.py| 2 +- BaseTools/Source/Python/FirmwareStorageFormat/UPLHeader.py | 244 6 files changed, 383 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/FMMT/FMMT.py b/BaseTools/Source/Python/FMMT/FMMT.py index bf580b3843..26fc4c5792 100644 --- a/BaseTools/Source/Python/FMMT/FMMT.py +++ b/BaseTools/Source/Python/FMMT/FMMT.py @@ -84,6 +84,8 @@ class FMMT(): ROOT_TYPE = ROOT_FFS_TREE elif filetype == '.sec': ROOT_TYPE = ROOT_SECTION_TREE +elif filetype == '.elf': +ROOT_TYPE = ROOT_ELF_TREE else: ROOT_TYPE = ROOT_TREE ViewFile(inputfile, ROOT_TYPE, layoutfilename, outputfile) diff --git a/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py b/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py index 2d4e6d9276..de174f26ab 100644 --- a/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py +++ b/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py @@ -15,10 +15,13 @@ from core.GuidTools import GUIDTools from utils.FmmtLogger import FmmtLogger as logger ROOT_TREE = 'ROOT' +ROOT_ELF_TREE = 'ROOT_ELF_TREE' ROOT_FV_TREE = 'ROOT_FV_TREE' ROOT_FFS_TREE = 'ROOT_FFS_TREE' ROOT_SECTION_TREE = 'ROOT_SECTION_TREE' +ELF_TREE = 'ELF' +ELF_SECTION_TREE = 'ELF_SECTION_TREE' FV_TREE = 'FV' DATA_FV_TREE = 'DATA_FV' FFS_TREE = 'FFS' @@ -49,6 +52,12 @@ class BinaryProduct(): def ParserData(): pass +class ElfFactory(BinaryFactory): +type = [ROOT_ELF_TREE, ELF_TREE] + +def Create_Product(): +return ElfProduct() + class SectionFactory(BinaryFactory): type = [SECTION_TREE] @@ -354,6 +363,30 @@ class FdProduct(BinaryProduct): tmp_index += 1 return Fd_Struct +class ElfSectionProduct(BinaryProduct): +## Decompress the compressed section. +def ParserData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +pass +def ParserSectionData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +pass +def ParserProgramData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +pass + +class ElfProduct(BinaryProduct): + +def ParserData(self, ParTree, Whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +Elf_Info = ElfNode(Whole_Data) +if Elf_Info.Header.ELF_PHOff != 0: +Elf_Info.GetProgramList(Whole_Data[Elf_Info.Header.ELF_PHOff:]) +if Elf_Info.Header.ELF_SHOff != 0: +Elf_Info.GetSectionList(Whole_Data[Elf_Info.Header.ELF_SHOff:]) +Elf_Info.FindUPLDSection(Whole_Data) +Elf_Tree = BIOSTREE(Elf_Info.Name) +Elf_Tree.type = ELF_TREE +Elf_Info.Data = Whole_Data[Elf_Info.HeaderLength:] +Elf_Tree.Data = Elf_Info +ParTree.insertChild(Elf_Tree) + class ParserEntry(): FactoryTable:dict = { SECTION_TREE: SectionFactory, @@ -364,6 +397,7 @@ class ParserEntry(): SEC_FV_TREE: FvFactory, ROOT_FV_TREE: FdFactory, ROOT_TREE: FdFactory, +ROOT_ELF_TREE: ElfFactory, } def GetTargetFactory(self, Tree_type: str) -> BinaryFactory: @@ -377,4 +411,4 @@ class ParserEntry(): def DataParser(self, Tree, Data: bytes, Offset: int) -> None: TargetFactory = self.GetTargetFactory(Tree.type) if TargetFactory: -self.Generate_Product(TargetFactory, Tree, Data, Offset) \ No newline at end of file +self.Generate_Product(TargetFactory, Tree, Data, Offset) diff --git a/BaseTools/Source/Python/FMMT/core/BiosTree.py
[edk2-devel] [Patch V1 3/3] 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 Cc: Bob Feng Cc: Liming Gao Signed-off-by: Yuwei Chen --- BaseTools/Source/Python/FMMT/FMMT.py | 2 ++ BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py | 36 +++- BaseTools/Source/Python/FMMT/core/BiosTree.py | 48 ++-- BaseTools/Source/Python/FMMT/core/BiosTreeNode.py | 56 +++- BaseTools/Source/Python/FMMT/core/FMMTParser.py| 2 +- BaseTools/Source/Python/FirmwareStorageFormat/UPLHeader.py | 244 6 files changed, 383 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/FMMT/FMMT.py b/BaseTools/Source/Python/FMMT/FMMT.py index bf580b3843..26fc4c5792 100644 --- a/BaseTools/Source/Python/FMMT/FMMT.py +++ b/BaseTools/Source/Python/FMMT/FMMT.py @@ -84,6 +84,8 @@ class FMMT(): ROOT_TYPE = ROOT_FFS_TREE elif filetype == '.sec': ROOT_TYPE = ROOT_SECTION_TREE +elif filetype == '.elf': +ROOT_TYPE = ROOT_ELF_TREE else: ROOT_TYPE = ROOT_TREE ViewFile(inputfile, ROOT_TYPE, layoutfilename, outputfile) diff --git a/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py b/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py index 2d4e6d9276..de174f26ab 100644 --- a/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py +++ b/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py @@ -15,10 +15,13 @@ from core.GuidTools import GUIDTools from utils.FmmtLogger import FmmtLogger as logger ROOT_TREE = 'ROOT' +ROOT_ELF_TREE = 'ROOT_ELF_TREE' ROOT_FV_TREE = 'ROOT_FV_TREE' ROOT_FFS_TREE = 'ROOT_FFS_TREE' ROOT_SECTION_TREE = 'ROOT_SECTION_TREE' +ELF_TREE = 'ELF' +ELF_SECTION_TREE = 'ELF_SECTION_TREE' FV_TREE = 'FV' DATA_FV_TREE = 'DATA_FV' FFS_TREE = 'FFS' @@ -49,6 +52,12 @@ class BinaryProduct(): def ParserData(): pass +class ElfFactory(BinaryFactory): +type = [ROOT_ELF_TREE, ELF_TREE] + +def Create_Product(): +return ElfProduct() + class SectionFactory(BinaryFactory): type = [SECTION_TREE] @@ -354,6 +363,30 @@ class FdProduct(BinaryProduct): tmp_index += 1 return Fd_Struct +class ElfSectionProduct(BinaryProduct): +## Decompress the compressed section. +def ParserData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +pass +def ParserSectionData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +pass +def ParserProgramData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +pass + +class ElfProduct(BinaryProduct): + +def ParserData(self, ParTree, Whole_Data: bytes, Rel_Whole_Offset: int=0) -> None: +Elf_Info = ElfNode(Whole_Data) +if Elf_Info.Header.ELF_PHOff != 0: +Elf_Info.GetProgramList(Whole_Data[Elf_Info.Header.ELF_PHOff:]) +if Elf_Info.Header.ELF_SHOff != 0: +Elf_Info.GetSectionList(Whole_Data[Elf_Info.Header.ELF_SHOff:]) +Elf_Info.FindUPLDSection(Whole_Data) +Elf_Tree = BIOSTREE(Elf_Info.Name) +Elf_Tree.type = ELF_TREE +Elf_Info.Data = Whole_Data[Elf_Info.HeaderLength:] +Elf_Tree.Data = Elf_Info +ParTree.insertChild(Elf_Tree) + class ParserEntry(): FactoryTable:dict = { SECTION_TREE: SectionFactory, @@ -364,6 +397,7 @@ class ParserEntry(): SEC_FV_TREE: FvFactory, ROOT_FV_TREE: FdFactory, ROOT_TREE: FdFactory, +ROOT_ELF_TREE: ElfFactory, } def GetTargetFactory(self, Tree_type: str) -> BinaryFactory: @@ -377,4 +411,4 @@ class ParserEntry(): def DataParser(self, Tree, Data: bytes, Offset: int) -> None: TargetFactory = self.GetTargetFactory(Tree.type) if TargetFactory: -self.Generate_Product(TargetFactory, Tree, Data, Offset) \ No newline at end of file +self.Generate_Product(TargetFactory, Tree, Data, Offset) diff --git a/BaseTools/Source/Python/FMMT/core/BiosTree.py b/BaseTools/Source/Python/FMMT/core/BiosTree.py index 137f49748b..c5a7b017f4 100644 --- a/BaseTools/Source/Python/FMMT/core/BiosTree.py +++ b/BaseTools/Source/Python/FMMT/core/BiosTree.py @@ -12,6 +12,7 @@ ROOT_TREE = 'ROOT' ROOT_FV_TREE = 'ROOT_FV_TREE' ROOT_FFS_TREE = 'ROOT_FFS_TREE'
[edk2-devel] [Patch V1 3/3] BaseTools: FMMT support ELF UPLD parser
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#103156): https://edk2.groups.io/g/devel/message/103156 Mute This Topic: https://groups.io/mt/98340352/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-