mirror of https://github.com/acidanthera/audk.git
Drop support for the TE format
This commit is contained in:
parent
c82eacb202
commit
a828c6cedf
|
@ -192,7 +192,7 @@ GetImageContext (
|
|||
return EFI_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
||||
if ((Section->Type == EFI_SECTION_PE32) || (Section->Type == EFI_SECTION_TE)) {
|
||||
if (Section->Type == EFI_SECTION_PE32) {
|
||||
EfiImage = (Section + 1);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import edk2_debugger
|
|||
class EfiFileSection(object):
|
||||
EFI_SECTION_PE32 = 0x10
|
||||
EFI_SECTION_PIC = 0x11
|
||||
EFI_SECTION_TE = 0x12
|
||||
|
||||
EFI_IMAGE_DEBUG_TYPE_CODEVIEW = 0x2
|
||||
|
||||
|
@ -38,58 +37,12 @@ class EfiFileSection(object):
|
|||
|
||||
def get_debug_filepath(self):
|
||||
type = self.get_type()
|
||||
if type == EfiFileSection.EFI_SECTION_TE:
|
||||
section = EfiSectionTE(self, ec, self.base + 0x4)
|
||||
elif type == EfiFileSection.EFI_SECTION_PE32:
|
||||
if type == EfiFileSection.EFI_SECTION_PE32:
|
||||
section = EfiSectionPE32(self, ec, self.base + 0x4)
|
||||
else:
|
||||
raise Exception("EfiFileSection", "No debug section")
|
||||
return section.get_debug_filepath()
|
||||
|
||||
class EfiSectionTE:
|
||||
SIZEOF_EFI_TE_IMAGE_HEADER = 0x28
|
||||
EFI_TE_IMAGE_SIGNATURE = ('V','Z')
|
||||
|
||||
def __init__(self, ec, base_te):
|
||||
self.ec = ec
|
||||
self.base_te = int(base_te)
|
||||
te_sig = struct.unpack("cc", self.ec.getMemoryService().read(self.base_te, 2, 32))
|
||||
if te_sig != EfiSectionTE.EFI_TE_IMAGE_SIGNATURE:
|
||||
raise Exception("EfiFileSectionTE","TE Signature incorrect")
|
||||
|
||||
def get_debug_filepath(self):
|
||||
stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]
|
||||
stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER
|
||||
|
||||
debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_te + 0x20)
|
||||
if debug_dir_entry_rva == 0:
|
||||
raise Exception("EfiFileSectionTE","No debug directory for image")
|
||||
debug_dir_entry_rva -= stripped_size
|
||||
|
||||
debug_type = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0xC)
|
||||
if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):
|
||||
raise Exception("EfiFileSectionTE","Debug type is not dwarf")
|
||||
|
||||
debug_rva = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0x14)
|
||||
debug_rva -= stripped_size
|
||||
|
||||
dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(self.base_te + debug_rva, 4, 32))
|
||||
if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):
|
||||
raise Exception("EfiFileSectionTE","Dwarf debug signature not found")
|
||||
|
||||
if dwarf_sig == 0x66727764:
|
||||
filename = self.base_te + debug_rva + 0xc
|
||||
else:
|
||||
filename = self.base_te + debug_rva + 0x10
|
||||
filename = struct.unpack("400s", self.ec.getMemoryService().read(filename, 400, 32))[0]
|
||||
return filename[0:string.find(filename,'\0')]
|
||||
|
||||
def get_debug_elfbase(self):
|
||||
stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]
|
||||
stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER
|
||||
|
||||
return self.base_te - stripped_size
|
||||
|
||||
class EfiSectionPE32:
|
||||
def __init__(self, ec, base_pe32):
|
||||
self.ec = ec
|
||||
|
@ -282,7 +235,7 @@ class FirmwareVolume:
|
|||
section = ffs.get_next_section()
|
||||
while section != None:
|
||||
type = section.get_type()
|
||||
if (type == EfiFileSection.EFI_SECTION_TE) or (type == EfiFileSection.EFI_SECTION_PE32):
|
||||
if (type == EfiFileSection.EFI_SECTION_PE32):
|
||||
self.DebugInfos.append((section.get_base(), section.get_size(), section.get_type()))
|
||||
section = ffs.get_next_section(section)
|
||||
ffs = self.get_next_ffs(ffs)
|
||||
|
@ -293,9 +246,7 @@ class FirmwareVolume:
|
|||
|
||||
for debug_info in self.DebugInfos:
|
||||
if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):
|
||||
if debug_info[2] == EfiFileSection.EFI_SECTION_TE:
|
||||
section = EfiSectionTE(self.ec, debug_info[0] + 0x4)
|
||||
elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:
|
||||
if debug_info[2] == EfiFileSection.EFI_SECTION_PE32:
|
||||
section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)
|
||||
else:
|
||||
raise Exception('FirmwareVolume','Section Type not supported')
|
||||
|
@ -313,9 +264,7 @@ class FirmwareVolume:
|
|||
self.get_debug_info()
|
||||
|
||||
for debug_info in self.DebugInfos:
|
||||
if debug_info[2] == EfiFileSection.EFI_SECTION_TE:
|
||||
section = EfiSectionTE(self.ec, debug_info[0] + 0x4)
|
||||
elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:
|
||||
if debug_info[2] == EfiFileSection.EFI_SECTION_PE32:
|
||||
section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)
|
||||
else:
|
||||
continue
|
||||
|
|
|
@ -36,24 +36,24 @@
|
|||
|
||||
[Rule.Common.SEC]
|
||||
FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED FIXED {
|
||||
TE TE Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
}
|
||||
|
||||
[Rule.Common.SEC.SELF_RELOC]
|
||||
FILE SEC = $(NAMED_GUID) {
|
||||
TE TE Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
}
|
||||
|
||||
[Rule.Common.PEI_CORE]
|
||||
FILE PEI_CORE = $(NAMED_GUID) FIXED {
|
||||
TE TE Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
UI STRING ="$(MODULE_NAME)" Optional
|
||||
}
|
||||
|
||||
[Rule.Common.PEIM]
|
||||
FILE PEIM = $(NAMED_GUID) FIXED {
|
||||
PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
|
||||
TE TE Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
|
||||
UI STRING="$(MODULE_NAME)" Optional
|
||||
}
|
||||
|
||||
|
|
|
@ -156,10 +156,6 @@ RelocateUefiImage (
|
|||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData, &SectionSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData, &SectionSize);
|
||||
}
|
||||
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = UefiImageInitializeContext (&ImageContext, SectionData, SectionSize);
|
||||
|
|
|
@ -496,7 +496,6 @@ class EfiSectionHeader(BinaryItem):
|
|||
0x02: 'EFI_SECTION_GUID_DEFINED',
|
||||
0x10: 'EFI_SECTION_PE32',
|
||||
0x11: 'EFI_SECTION_PIC',
|
||||
0x12: 'EFI_SECTION_TE',
|
||||
0x13: 'EFI_SECTION_DXE_DEPEX',
|
||||
0x14: 'EFI_SECTION_VERSION',
|
||||
0x15: 'EFI_SECTION_USER_INTERFACE',
|
||||
|
|
|
@ -167,21 +167,6 @@ class EFI_IMAGE_DATA_DIRECTORY(LittleEndianStructure):
|
|||
]
|
||||
|
||||
|
||||
class EFI_TE_IMAGE_HEADER(LittleEndianStructure):
|
||||
_fields_ = [
|
||||
('Signature', ARRAY(c_char, 2)),
|
||||
('Machine', c_uint16),
|
||||
('NumberOfSections', c_uint8),
|
||||
('Subsystem', c_uint8),
|
||||
('StrippedSize', c_uint16),
|
||||
('AddressOfEntryPoint', c_uint32),
|
||||
('BaseOfCode', c_uint32),
|
||||
('ImageBase', c_uint64),
|
||||
('DataDirectoryBaseReloc', EFI_IMAGE_DATA_DIRECTORY),
|
||||
('DataDirectoryDebug', EFI_IMAGE_DATA_DIRECTORY)
|
||||
]
|
||||
|
||||
|
||||
class EFI_IMAGE_DOS_HEADER(LittleEndianStructure):
|
||||
_fields_ = [
|
||||
('e_magic', c_uint16),
|
||||
|
@ -1837,9 +1822,9 @@ class EfiConfigurationTable:
|
|||
return ImageLoad
|
||||
|
||||
|
||||
class PeTeImage:
|
||||
class PeImage:
|
||||
'''
|
||||
A class to abstract PE/COFF or TE image processing via passing in a
|
||||
A class to abstract PE/COFF image processing via passing in a
|
||||
Python file like object. If you pass in an address the PE/COFF is parsed,
|
||||
if you pass in NULL for an address then you get a class instance you can
|
||||
use to search memory for a PE/COFF hader given a pc value.
|
||||
|
@ -1872,7 +1857,6 @@ class PeTeImage:
|
|||
|
||||
# book keeping, but public
|
||||
self.PeHdr = None
|
||||
self.TeHdr = None
|
||||
self.Machine = None
|
||||
self.Subsystem = None
|
||||
self.CodeViewSig = None
|
||||
|
@ -1888,7 +1872,6 @@ class PeTeImage:
|
|||
self.DataAddress = 0
|
||||
self.CodeViewPdb = None
|
||||
self.CodeViewUuid = None
|
||||
self.TeAdjust = 0
|
||||
|
||||
self.dir_name = {
|
||||
0: 'Export Table',
|
||||
|
@ -1914,9 +1897,9 @@ class PeTeImage:
|
|||
self.parse()
|
||||
|
||||
def __str__(self):
|
||||
if self.PeHdr is None and self.TeHdr is None:
|
||||
if self.PeHdr is None:
|
||||
# no PE/COFF header found
|
||||
return "<class: PeTeImage>"
|
||||
return "<class: PeImage>"
|
||||
|
||||
if self.CodeViewPdb:
|
||||
pdb = f'{self.Machine}`{self.CodeViewPdb}'
|
||||
|
@ -1928,8 +1911,7 @@ class PeTeImage:
|
|||
else:
|
||||
guid = ''
|
||||
|
||||
slide = f'slide = {self.TeAdjust:d} ' if self.TeAdjust != 0 else ' '
|
||||
res = guid + f'{pdb} load = 0x{self.LoadAddress:08x} ' + slide
|
||||
res = guid + f'{pdb} load = 0x{self.LoadAddress:08x} '
|
||||
return res
|
||||
|
||||
def _seek(self, offset):
|
||||
|
@ -1989,60 +1971,46 @@ class PeTeImage:
|
|||
return False
|
||||
|
||||
def maybe(self, offset=None):
|
||||
"""Probe to see if this offset is likely a PE/COFF or TE file """
|
||||
"""Probe to see if this offset is likely a PE/COFF file """
|
||||
self.LoadAddress = 0
|
||||
e_magic = self._read_offset(2, offset)
|
||||
header_ok = e_magic == b'MZ' or e_magic == b'VZ'
|
||||
header_ok = e_magic == b'MZ'
|
||||
if offset is not None and header_ok:
|
||||
self.LoadAddress = offset
|
||||
return header_ok
|
||||
|
||||
def parse(self):
|
||||
"""Parse PE/COFF (TE) debug directory entry """
|
||||
"""Parse PE/COFF debug directory entry """
|
||||
DosHdr = self._read_ctype(EFI_IMAGE_DOS_HEADER, 0)
|
||||
if DosHdr.e_magic == self._unsigned(b'VZ'):
|
||||
# TE image
|
||||
self.TeHdr = self._read_ctype(EFI_TE_IMAGE_HEADER, 0)
|
||||
|
||||
self.TeAdjust = sizeof(self.TeHdr) - self.TeHdr.StrippedSize
|
||||
self.Machine = image_machine_dict.get(self.TeHdr.Machine, None)
|
||||
self.Subsystem = self.TeHdr.Subsystem
|
||||
self.AddressOfEntryPoint = self.TeHdr.AddressOfEntryPoint
|
||||
|
||||
debug_dir_size = self.TeHdr.DataDirectoryDebug.Size
|
||||
debug_dir_offset = (self.TeAdjust +
|
||||
self.TeHdr.DataDirectoryDebug.VirtualAddress)
|
||||
if DosHdr.e_magic == self._unsigned(b'MZ'):
|
||||
self.e_lfanew = DosHdr.e_lfanew
|
||||
else:
|
||||
if DosHdr.e_magic == self._unsigned(b'MZ'):
|
||||
self.e_lfanew = DosHdr.e_lfanew
|
||||
else:
|
||||
self.e_lfanew = 0
|
||||
self.e_lfanew = 0
|
||||
|
||||
self.PeHdr = self._read_ctype(
|
||||
EFI_IMAGE_NT_HEADERS64, self.e_lfanew)
|
||||
if self.PeHdr.Signature != self._unsigned(b'PE\0\0'):
|
||||
return False
|
||||
|
||||
if self.PeHdr.OptionalHeader.Magic == \
|
||||
EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC:
|
||||
self.PeHdr = self._read_ctype(
|
||||
EFI_IMAGE_NT_HEADERS64, self.e_lfanew)
|
||||
if self.PeHdr.Signature != self._unsigned(b'PE\0\0'):
|
||||
return False
|
||||
EFI_IMAGE_NT_HEADERS32, self.e_lfanew)
|
||||
|
||||
if self.PeHdr.OptionalHeader.Magic == \
|
||||
EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC:
|
||||
self.PeHdr = self._read_ctype(
|
||||
EFI_IMAGE_NT_HEADERS32, self.e_lfanew)
|
||||
if self.PeHdr.OptionalHeader.NumberOfRvaAndSizes <= \
|
||||
DIRECTORY_DEBUG:
|
||||
return False
|
||||
|
||||
if self.PeHdr.OptionalHeader.NumberOfRvaAndSizes <= \
|
||||
DIRECTORY_DEBUG:
|
||||
return False
|
||||
self.Machine = image_machine_dict.get(
|
||||
self.PeHdr.FileHeader.Machine, None)
|
||||
self.Subsystem = self.PeHdr.OptionalHeader.Subsystem
|
||||
self.AddressOfEntryPoint = \
|
||||
self.PeHdr.OptionalHeader.AddressOfEntryPoint
|
||||
|
||||
self.Machine = image_machine_dict.get(
|
||||
self.PeHdr.FileHeader.Machine, None)
|
||||
self.Subsystem = self.PeHdr.OptionalHeader.Subsystem
|
||||
self.AddressOfEntryPoint = \
|
||||
self.PeHdr.OptionalHeader.AddressOfEntryPoint
|
||||
self.TeAdjust = 0
|
||||
|
||||
debug_dir_size = self.PeHdr.OptionalHeader.DataDirectory[
|
||||
DIRECTORY_DEBUG].Size
|
||||
debug_dir_offset = self.PeHdr.OptionalHeader.DataDirectory[
|
||||
DIRECTORY_DEBUG].VirtualAddress
|
||||
debug_dir_size = self.PeHdr.OptionalHeader.DataDirectory[
|
||||
DIRECTORY_DEBUG].Size
|
||||
debug_dir_offset = self.PeHdr.OptionalHeader.DataDirectory[
|
||||
DIRECTORY_DEBUG].VirtualAddress
|
||||
|
||||
if self.Machine is None or self.Subsystem not in [0, 10, 11, 12]:
|
||||
return False
|
||||
|
@ -2056,10 +2024,7 @@ class PeTeImage:
|
|||
'''Parse the PE/COFF (TE) section table'''
|
||||
if self.Sections is not None:
|
||||
return
|
||||
elif self.TeHdr is not None:
|
||||
self.NumberOfSections = self.TeHdr.NumberOfSections
|
||||
offset = sizeof(EFI_TE_IMAGE_HEADER)
|
||||
elif self.PeHdr is not None:
|
||||
if self.PeHdr is not None:
|
||||
self.NumberOfSections = self.PeHdr.FileHeader.NumberOfSections
|
||||
offset = sizeof(c_uint32) + \
|
||||
sizeof(EFI_IMAGE_FILE_HEADER)
|
||||
|
@ -2074,7 +2039,7 @@ class PeTeImage:
|
|||
for i in range(self.NumberOfSections):
|
||||
name = str(self.Sections[i].Name, 'ascii', 'ignore')
|
||||
addr = self.Sections[i].VirtualAddress
|
||||
addr += self.LoadAddress + self.TeAdjust
|
||||
addr += self.LoadAddress
|
||||
if name == '.text':
|
||||
self.TextAddress = addr
|
||||
elif name == '.data':
|
||||
|
@ -2099,22 +2064,7 @@ class PeTeImage:
|
|||
|
||||
def directory_to_str(self):
|
||||
result = ''
|
||||
if self.TeHdr:
|
||||
debug_size = self.TeHdr.DataDirectoryDebug.Size
|
||||
if debug_size > 0:
|
||||
debug_offset = (self.TeAdjust
|
||||
+ self.TeHdr.DataDirectoryDebug.VirtualAddress)
|
||||
result += f"Debug 0x{debug_offset:08X} 0x{debug_size}\n"
|
||||
|
||||
relocation_size = self.TeHdr.DataDirectoryBaseReloc.Size
|
||||
if relocation_size > 0:
|
||||
relocation_offset = (
|
||||
self.TeAdjust
|
||||
+ self.TeHdr.DataDirectoryBaseReloc.VirtualAddress)
|
||||
result += f'Relocation 0x{relocation_offset:08X} '
|
||||
result += f' 0x{relocation_size}\n'
|
||||
|
||||
elif self.PeHdr:
|
||||
if self.PeHdr:
|
||||
for i in range(self.PeHdr.OptionalHeader.NumberOfRvaAndSizes):
|
||||
size = self.PeHdr.OptionalHeader.DataDirectory[i].Size
|
||||
if size == 0:
|
||||
|
@ -2143,7 +2093,7 @@ class PeTeImage:
|
|||
continue
|
||||
|
||||
entry = self._read_offset(
|
||||
DirectoryEntry.SizeOfData, DirectoryEntry.RVA + self.TeAdjust)
|
||||
DirectoryEntry.SizeOfData, DirectoryEntry.RVA)
|
||||
self.CodeViewSig = entry[:4]
|
||||
if self.CodeViewSig == b'MTOC':
|
||||
self.CodeViewUuid = uuid.UUID(bytes_le=entry[4:4+16])
|
||||
|
@ -2170,7 +2120,7 @@ def main():
|
|||
'''Process arguments as PE/COFF files'''
|
||||
for fname in sys.argv[1:]:
|
||||
with open(fname, 'rb') as f:
|
||||
image = PeTeImage(f)
|
||||
image = PeImage(f)
|
||||
print(image)
|
||||
res = f'EntryPoint = 0x{image.AddressOfEntryPoint:08x} '
|
||||
res += f'TextAddress = 0x{image.TextAddress:08x} '
|
||||
|
|
|
@ -41,7 +41,7 @@ import shlex
|
|||
# so lets fix that for gdb...
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from efi_debugging import PeTeImage, patch_ctypes # noqa: E402
|
||||
from efi_debugging import PeImage, patch_ctypes # noqa: E402
|
||||
from efi_debugging import EfiHob, GuidNames, EfiStatusClass # noqa: E402
|
||||
from efi_debugging import EfiBootMode, EfiDevicePath # noqa: E402
|
||||
from efi_debugging import EfiConfigurationTable, EfiTpl # noqa: E402
|
||||
|
@ -155,7 +155,7 @@ class EfiSymbols:
|
|||
@ classmethod
|
||||
def address_to_symbols(cls, address, reprobe=False):
|
||||
'''
|
||||
Given an address search backwards for a PE/COFF (or TE) header
|
||||
Given an address search backwards for a PE/COFF header
|
||||
and load symbols. Return a status string.
|
||||
'''
|
||||
if not isinstance(address, int):
|
||||
|
@ -166,12 +166,12 @@ class EfiSymbols:
|
|||
# skip the probe of the remote
|
||||
return f'{pecoff} is already loaded'
|
||||
|
||||
pecoff = PeTeImage(cls.file, None)
|
||||
pecoff = PeImage(cls.file, None)
|
||||
if pecoff.pcToPeCoff(address, cls.stride, cls.range):
|
||||
res = cls.add_symbols_for_pecoff(pecoff)
|
||||
return f'{res}{pecoff}'
|
||||
else:
|
||||
return f'0x{address:08x} not in a PE/COFF (or TE) image'
|
||||
return f'0x{address:08x} not in a PE/COFF image'
|
||||
|
||||
@ classmethod
|
||||
def address_in_loaded_pecoff(cls, address):
|
||||
|
@ -289,7 +289,7 @@ class EfiDevicePathCmd (gdb.Command):
|
|||
def create_options(self, arg, from_tty):
|
||||
usage = "usage: %prog [options] [arg]"
|
||||
description = (
|
||||
"Command that can load EFI PE/COFF and TE image symbols. ")
|
||||
"Command that can load EFI PE/COFF image symbols. ")
|
||||
|
||||
self.parser = optparse.OptionParser(
|
||||
description=description,
|
||||
|
@ -461,7 +461,7 @@ class EfiHobCmd (gdb.Command):
|
|||
def create_options(self, arg, from_tty):
|
||||
usage = "usage: %prog [options] [arg]"
|
||||
description = (
|
||||
"Command that can load EFI PE/COFF and TE image symbols. ")
|
||||
"Command that can load EFI PE/COFF image symbols. ")
|
||||
|
||||
self.parser = optparse.OptionParser(
|
||||
description=description,
|
||||
|
@ -595,9 +595,9 @@ class EfiSymbolsCmd (gdb.Command):
|
|||
def create_options(self, arg, from_tty):
|
||||
usage = "usage: %prog [options]"
|
||||
description = (
|
||||
"Command that can load EFI PE/COFF and TE image symbols. "
|
||||
"Command that can load EFI PE/COFF image symbols. "
|
||||
"If you are having trouble in PEI try adding --pei. "
|
||||
"Given any address search backward for the PE/COFF (or TE header) "
|
||||
"Given any address search backward for the PE/COFF "
|
||||
"and then parse the PE/COFF image to get debug info. "
|
||||
"The address can come from the current pc, pc values in the "
|
||||
"frame, or an address provided to the command"
|
||||
|
|
|
@ -17,7 +17,7 @@ import os
|
|||
from pathlib import Path
|
||||
from efi_debugging import EfiDevicePath, EfiConfigurationTable, EfiTpl
|
||||
from efi_debugging import EfiHob, GuidNames, EfiStatusClass, EfiBootMode
|
||||
from efi_debugging import PeTeImage, patch_ctypes
|
||||
from efi_debugging import PeImage, patch_ctypes
|
||||
|
||||
try:
|
||||
# Just try for LLDB in case PYTHONPATH is already correctly setup
|
||||
|
@ -144,7 +144,7 @@ class EfiSymbols:
|
|||
str(pecoff.CodeViewUuid))
|
||||
if module.IsValid():
|
||||
SBError = cls.target.SetModuleLoadAddress(
|
||||
module, pecoff.LoadAddress + pecoff.TeAdjust)
|
||||
module, pecoff.LoadAddress)
|
||||
if SBError.success:
|
||||
cls.loaded[pecoff.LoadAddress] = (pecoff, module)
|
||||
return ''
|
||||
|
@ -154,7 +154,7 @@ class EfiSymbols:
|
|||
@ classmethod
|
||||
def address_to_symbols(cls, address, reprobe=False):
|
||||
'''
|
||||
Given an address search backwards for a PE/COFF (or TE) header
|
||||
Given an address search backwards for a PE/COFF header
|
||||
and load symbols. Return a status string.
|
||||
'''
|
||||
if not isinstance(address, int):
|
||||
|
@ -165,12 +165,12 @@ class EfiSymbols:
|
|||
# skip the probe of the remote
|
||||
return f'{pecoff} is already loaded'
|
||||
|
||||
pecoff = PeTeImage(cls._file, None)
|
||||
pecoff = PeImage(cls._file, None)
|
||||
if pecoff.pcToPeCoff(address, cls.stride, cls.range):
|
||||
res = cls.add_symbols_for_pecoff(pecoff)
|
||||
return f'{res}{pecoff}'
|
||||
else:
|
||||
return f'0x{address:08x} not in a PE/COFF (or TE) image'
|
||||
return f'0x{address:08x} not in a PE/COFF image'
|
||||
|
||||
@ classmethod
|
||||
def address_in_loaded_pecoff(cls, address):
|
||||
|
@ -596,7 +596,7 @@ class EfiSymbolicateCommand(object):
|
|||
def create_options(self):
|
||||
''' standard lldb command help/options parser'''
|
||||
usage = "usage: %prog [options]"
|
||||
description = '''Command that can load EFI PE/COFF and TE image
|
||||
description = '''Command that can load EFI PE/COFF image
|
||||
symbols. If you are having trouble in PEI try adding --pei.
|
||||
'''
|
||||
|
||||
|
|
|
@ -285,7 +285,7 @@ Arguments:
|
|||
|
||||
MaxAlignment - The max alignment required by all the input file datas.
|
||||
|
||||
PeSectionNum - Calculate the number of Pe/Te Section in this FFS file.
|
||||
PeSectionNum - Calculate the number of Pe Section in this FFS file.
|
||||
|
||||
Returns:
|
||||
|
||||
|
@ -302,8 +302,6 @@ Returns:
|
|||
FILE *InFile;
|
||||
EFI_FREEFORM_SUBTYPE_GUID_SECTION *SectHeader;
|
||||
EFI_COMMON_SECTION_HEADER2 TempSectHeader;
|
||||
EFI_TE_IMAGE_HEADER TeHeader;
|
||||
UINT32 TeOffset;
|
||||
EFI_GUID_DEFINED_SECTION GuidSectHeader;
|
||||
EFI_GUID_DEFINED_SECTION2 GuidSectHeader2;
|
||||
UINT32 HeaderSize;
|
||||
|
@ -311,7 +309,6 @@ Returns:
|
|||
|
||||
Size = 0;
|
||||
Offset = 0;
|
||||
TeOffset = 0;
|
||||
MaxEncounteredAlignment = 1;
|
||||
|
||||
//
|
||||
|
@ -342,22 +339,15 @@ Returns:
|
|||
"the input section name is %s and the size is %u bytes", InputFileName[Index], (unsigned) FileSize);
|
||||
|
||||
//
|
||||
// Check this section is Te/Pe section, and Calculate the numbers of Te/Pe section.
|
||||
// Check this section is Pe section, and Calculate the numbers of Pe section.
|
||||
//
|
||||
TeOffset = 0;
|
||||
if (FileSize >= MAX_FFS_SIZE) {
|
||||
HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER2);
|
||||
} else {
|
||||
HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER);
|
||||
}
|
||||
fread (&TempSectHeader, 1, HeaderSize, InFile);
|
||||
if (TempSectHeader.Type == EFI_SECTION_TE) {
|
||||
(*PESectionNum) ++;
|
||||
fread (&TeHeader, 1, sizeof (TeHeader), InFile);
|
||||
if (TeHeader.Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
|
||||
TeOffset = TeHeader.StrippedSize - sizeof (TeHeader);
|
||||
}
|
||||
} else if (TempSectHeader.Type == EFI_SECTION_PE32) {
|
||||
if (TempSectHeader.Type == EFI_SECTION_PE32) {
|
||||
(*PESectionNum) ++;
|
||||
} else if (TempSectHeader.Type == EFI_SECTION_GUID_DEFINED) {
|
||||
fseek (InFile, 0, SEEK_SET);
|
||||
|
@ -376,30 +366,21 @@ Returns:
|
|||
} else if (TempSectHeader.Type == EFI_SECTION_COMPRESSION ||
|
||||
TempSectHeader.Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {
|
||||
//
|
||||
// for the encapsulated section, assume it contains Pe/Te section
|
||||
// for the encapsulated section, assume it contains Pe section
|
||||
//
|
||||
(*PESectionNum) ++;
|
||||
}
|
||||
|
||||
fseek (InFile, 0, SEEK_SET);
|
||||
|
||||
//
|
||||
// Revert TeOffset to the converse value relative to Alignment
|
||||
// This is to assure the original PeImage Header at Alignment.
|
||||
//
|
||||
if ((TeOffset != 0) && (InputFileAlign [Index] != 0)) {
|
||||
TeOffset = InputFileAlign [Index] - (TeOffset % InputFileAlign [Index]);
|
||||
TeOffset = TeOffset % InputFileAlign [Index];
|
||||
}
|
||||
|
||||
//
|
||||
// make sure section data meet its alignment requirement by adding one pad section.
|
||||
// But the different sections have the different section header. Necessary or not?
|
||||
// Based on section type to adjust offset? Todo
|
||||
//
|
||||
if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize + TeOffset) % InputFileAlign [Index]) != 0)) {
|
||||
Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + TeOffset + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1);
|
||||
Offset = Offset - Size - HeaderSize - TeOffset;
|
||||
if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize) % InputFileAlign [Index]) != 0)) {
|
||||
Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1);
|
||||
Offset = Offset - Size - HeaderSize;
|
||||
|
||||
if (FileBuffer != NULL && ((Size + Offset) < *BufferLength)) {
|
||||
//
|
||||
|
@ -959,7 +940,7 @@ Returns:
|
|||
if ((FfsFiletype == EFI_FV_FILETYPE_SECURITY_CORE ||
|
||||
FfsFiletype == EFI_FV_FILETYPE_PEI_CORE ||
|
||||
FfsFiletype == EFI_FV_FILETYPE_DXE_CORE) && (PeSectionNum != 1)) {
|
||||
Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have one and only one Pe or Te section, but %u Pe/Te section are input", mFfsFileType [FfsFiletype], PeSectionNum);
|
||||
Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have one and only one Pe section, but %u Pe section are input", mFfsFileType [FfsFiletype], PeSectionNum);
|
||||
goto Finish;
|
||||
}
|
||||
|
||||
|
@ -967,7 +948,7 @@ Returns:
|
|||
FfsFiletype == EFI_FV_FILETYPE_DRIVER ||
|
||||
FfsFiletype == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER ||
|
||||
FfsFiletype == EFI_FV_FILETYPE_APPLICATION) && (PeSectionNum < 1)) {
|
||||
Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have at least one Pe or Te section, but no Pe/Te section is input", mFfsFileType [FfsFiletype]);
|
||||
Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have at least one Pe section, but no Pe section is input", mFfsFileType [FfsFiletype]);
|
||||
goto Finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -759,7 +759,6 @@ Returns:
|
|||
UINT32 AddressOfEntryPoint;
|
||||
UINT32 Offset;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
|
||||
EFI_TE_IMAGE_HEADER *TEImageHeader;
|
||||
EFI_IMAGE_SECTION_HEADER *SectionHeader;
|
||||
long long TempLongAddress;
|
||||
UINT32 TextVirtualAddress;
|
||||
|
@ -830,24 +829,18 @@ Returns:
|
|||
//
|
||||
// AddressOfEntryPoint and Offset in Image
|
||||
//
|
||||
if (!pImageContext->IsTeImage) {
|
||||
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINT8 *) pImageContext->Handle + pImageContext->PeCoffHeaderOffset);
|
||||
AddressOfEntryPoint = ImgHdr->Pe32.OptionalHeader.AddressOfEntryPoint;
|
||||
Offset = 0;
|
||||
SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (
|
||||
(UINT8 *) ImgHdr +
|
||||
sizeof (UINT32) +
|
||||
sizeof (EFI_IMAGE_FILE_HEADER) +
|
||||
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
|
||||
);
|
||||
Index = ImgHdr->Pe32.FileHeader.NumberOfSections;
|
||||
} else {
|
||||
TEImageHeader = (EFI_TE_IMAGE_HEADER *) pImageContext->Handle;
|
||||
AddressOfEntryPoint = TEImageHeader->AddressOfEntryPoint;
|
||||
Offset = TEImageHeader->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);
|
||||
SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (TEImageHeader + 1);
|
||||
Index = TEImageHeader->NumberOfSections;
|
||||
}
|
||||
assert (!pImageContext->IsTeImage);
|
||||
|
||||
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINT8 *) pImageContext->Handle + pImageContext->PeCoffHeaderOffset);
|
||||
AddressOfEntryPoint = ImgHdr->Pe32.OptionalHeader.AddressOfEntryPoint;
|
||||
Offset = 0;
|
||||
SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (
|
||||
(UINT8 *) ImgHdr +
|
||||
sizeof (UINT32) +
|
||||
sizeof (EFI_IMAGE_FILE_HEADER) +
|
||||
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
|
||||
);
|
||||
Index = ImgHdr->Pe32.FileHeader.NumberOfSections;
|
||||
|
||||
//
|
||||
// module information output
|
||||
|
@ -861,11 +854,7 @@ Returns:
|
|||
}
|
||||
|
||||
fprintf (FvMapFile, "EntryPoint=0x%010llx, ", (unsigned long long) (ImageBaseAddress + AddressOfEntryPoint));
|
||||
if (!pImageContext->IsTeImage) {
|
||||
fprintf (FvMapFile, "Type=PE");
|
||||
} else {
|
||||
fprintf (FvMapFile, "Type=TE");
|
||||
}
|
||||
fprintf (FvMapFile, "Type=PE");
|
||||
fprintf (FvMapFile, ")\n");
|
||||
|
||||
fprintf (FvMapFile, "(GUID=%s", FileGuidName);
|
||||
|
@ -1296,7 +1285,7 @@ Returns:
|
|||
return EFI_ABORTED;
|
||||
}
|
||||
//
|
||||
// Rebase the PE or TE image in FileBuffer of FFS file for XIP
|
||||
// Rebase the PE image in FileBuffer of FFS file for XIP
|
||||
// Rebase for the debug genfvmap tool
|
||||
//
|
||||
Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER **)&FileBuffer, &FileSize, (UINTN) *VtfFileImage - (UINTN) FvImage->FileImage, FvMapFile);
|
||||
|
@ -1348,7 +1337,7 @@ Returns:
|
|||
//
|
||||
if ((UINTN) (FvImage->CurrentFilePointer + FileSize) <= (UINTN) (*VtfFileImage)) {
|
||||
//
|
||||
// Rebase the PE or TE image in FileBuffer of FFS file for XIP.
|
||||
// Rebase the PE image in FileBuffer of FFS file for XIP.
|
||||
// Rebase Bs and Rt drivers for the debug genfvmap tool.
|
||||
//
|
||||
Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER **)&FileBuffer, &FileSize, (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage, FvMapFile);
|
||||
|
@ -1579,10 +1568,6 @@ Returns:
|
|||
// Sec Core found, now find PE32 section
|
||||
//
|
||||
Status = GetSectionByType (SecCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
Status = GetSectionByType (SecCoreFile, EFI_SECTION_TE, 1, &Pe32Section);
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 3000, "Invalid", "could not find a PE32 section in the SEC core file.");
|
||||
return EFI_ABORTED;
|
||||
|
@ -1628,15 +1613,11 @@ Returns:
|
|||
Status = GetFileByType (EFI_FV_FILETYPE_PEI_CORE, 1, &PeiCoreFile);
|
||||
if (!EFI_ERROR (Status) && (PeiCoreFile != NULL)) {
|
||||
//
|
||||
// PEI Core found, now find PE32 or TE section
|
||||
// PEI Core found, now find PE32 section
|
||||
//
|
||||
Status = GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
Status = GetSectionByType (PeiCoreFile, EFI_SECTION_TE, 1, &Pe32Section);
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 3000, "Invalid", "could not find either a PE32 or a TE section in PEI core file.");
|
||||
Error (NULL, 0, 3000, "Invalid", "could not find either a PE32 section in PEI core file.");
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
|
||||
|
@ -1785,13 +1766,9 @@ Returns:
|
|||
if (!EFI_ERROR(Status) && (CoreFfsFile != NULL) ) {
|
||||
|
||||
//
|
||||
// Core found, now find PE32 or TE section
|
||||
// Core found, now find PE32 section
|
||||
//
|
||||
Status = GetSectionByType(CoreFfsFile, EFI_SECTION_PE32, 1, Pe32Section);
|
||||
if (EFI_ERROR(Status)) {
|
||||
Status = GetSectionByType(CoreFfsFile, EFI_SECTION_TE, 1, Pe32Section);
|
||||
}
|
||||
|
||||
if (EFI_ERROR(Status)) {
|
||||
Error(NULL, 0, 3000, "Invalid", "could not find a PE32 section in the core file.");
|
||||
return EFI_ABORTED;
|
||||
|
@ -2418,7 +2395,6 @@ Returns:
|
|||
{
|
||||
EFI_IMAGE_DOS_HEADER *DosHeader;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
|
||||
EFI_TE_IMAGE_HEADER *TeHeader;
|
||||
|
||||
//
|
||||
// Verify input parameters
|
||||
|
@ -2428,48 +2404,35 @@ Returns:
|
|||
}
|
||||
|
||||
//
|
||||
// First check whether it is one TE Image.
|
||||
// Check whether
|
||||
// First is the DOS header
|
||||
//
|
||||
TeHeader = (EFI_TE_IMAGE_HEADER *) Pe32;
|
||||
if (TeHeader->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
|
||||
//
|
||||
// By TeImage Header to get output
|
||||
//
|
||||
*EntryPoint = TeHeader->AddressOfEntryPoint + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader->StrippedSize;
|
||||
*MachineType = TeHeader->Machine;
|
||||
} else {
|
||||
DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;
|
||||
|
||||
//
|
||||
// Then check whether
|
||||
// First is the DOS header
|
||||
//
|
||||
DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;
|
||||
|
||||
//
|
||||
// Verify DOS header is expected
|
||||
//
|
||||
if (DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
|
||||
Error (NULL, 0, 3000, "Invalid", "Unknown magic number in the DOS header, 0x%04X.", DosHeader->e_magic);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// Immediately following is the NT header.
|
||||
//
|
||||
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINTN) Pe32 + DosHeader->e_lfanew);
|
||||
|
||||
//
|
||||
// Verify NT header is expected
|
||||
//
|
||||
if (ImgHdr->Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {
|
||||
Error (NULL, 0, 3000, "Invalid", "Unrecognized image signature 0x%08X.", (unsigned) ImgHdr->Pe32.Signature);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// Get output
|
||||
//
|
||||
*EntryPoint = ImgHdr->Pe32.OptionalHeader.AddressOfEntryPoint;
|
||||
*MachineType = ImgHdr->Pe32.FileHeader.Machine;
|
||||
//
|
||||
// Verify DOS header is expected
|
||||
//
|
||||
if (DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
|
||||
Error (NULL, 0, 3000, "Invalid", "Unknown magic number in the DOS header, 0x%04X.", DosHeader->e_magic);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// Immediately following is the NT header.
|
||||
//
|
||||
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINTN) Pe32 + DosHeader->e_lfanew);
|
||||
|
||||
//
|
||||
// Verify NT header is expected
|
||||
//
|
||||
if (ImgHdr->Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {
|
||||
Error (NULL, 0, 3000, "Invalid", "Unrecognized image signature 0x%08X.", (unsigned) ImgHdr->Pe32.Signature);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// Get output
|
||||
//
|
||||
*EntryPoint = ImgHdr->Pe32.OptionalHeader.AddressOfEntryPoint;
|
||||
*MachineType = ImgHdr->Pe32.FileHeader.Machine;
|
||||
|
||||
//
|
||||
// Verify machine type is supported
|
||||
|
@ -3589,7 +3552,6 @@ Returns:
|
|||
EFI_FILE_SECTION_POINTER CurrentPe32Section;
|
||||
EFI_FFS_FILE_STATE SavedState;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
|
||||
EFI_TE_IMAGE_HEADER *TEImageHeader;
|
||||
UINT8 *MemoryImagePointer;
|
||||
EFI_IMAGE_SECTION_HEADER *SectionHeader;
|
||||
CHAR8 PeFileName [MAX_LONG_FILE_PATH];
|
||||
|
@ -3603,7 +3565,6 @@ Returns:
|
|||
|
||||
Index = 0;
|
||||
MemoryImagePointer = NULL;
|
||||
TEImageHeader = NULL;
|
||||
ImgHdr = NULL;
|
||||
SectionHeader = NULL;
|
||||
Cptr = NULL;
|
||||
|
@ -3936,248 +3897,6 @@ Returns:
|
|||
WriteMapFile (FvMapFile, PdbPointer, *FfsFile, NewPe32BaseAddress, &ImageContext);
|
||||
}
|
||||
|
||||
if ((*FfsFile)->Type != EFI_FV_FILETYPE_SECURITY_CORE &&
|
||||
(*FfsFile)->Type != EFI_FV_FILETYPE_PEI_CORE &&
|
||||
(*FfsFile)->Type != EFI_FV_FILETYPE_PEIM &&
|
||||
(*FfsFile)->Type != EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER &&
|
||||
(*FfsFile)->Type != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
|
||||
) {
|
||||
//
|
||||
// Only Peim code may have a TE section
|
||||
//
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Now process TE sections
|
||||
//
|
||||
for (Index = 1;; Index++) {
|
||||
NewPe32BaseAddress = 0;
|
||||
|
||||
//
|
||||
// Find Te Image
|
||||
//
|
||||
Status = GetSectionByType (*FfsFile, EFI_SECTION_TE, Index, &CurrentPe32Section);
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
CurSecHdrSize = GetSectionHeaderLength(CurrentPe32Section.CommonHeader);
|
||||
|
||||
//
|
||||
// Calculate the TE base address, the FFS file base plus the offset of the TE section less the size stripped off
|
||||
// by GenTEImage
|
||||
//
|
||||
TEImageHeader = (EFI_TE_IMAGE_HEADER *) ((UINT8 *) CurrentPe32Section.Pe32Section + CurSecHdrSize);
|
||||
|
||||
//
|
||||
// Initialize context, load image info.
|
||||
//
|
||||
memset (&ImageContext, 0, sizeof (ImageContext));
|
||||
ImageContext.Handle = (VOID *) TEImageHeader;
|
||||
ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;
|
||||
Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 3000, "Invalid TeImage", "The input file is %s and the return status is %x", FileName, (int) Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
if ( (ImageContext.Machine == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) ||
|
||||
(ImageContext.Machine == IMAGE_FILE_MACHINE_ARM64) ) {
|
||||
mArm = TRUE;
|
||||
}
|
||||
|
||||
if (ImageContext.Machine == IMAGE_FILE_MACHINE_LOONGARCH64) {
|
||||
mLoongArch = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Keep Image Context for TE image in FV
|
||||
//
|
||||
memcpy (&OrigImageContext, &ImageContext, sizeof (ImageContext));
|
||||
|
||||
//
|
||||
// Get File PdbPointer
|
||||
//
|
||||
PdbPointer = PeCoffLoaderGetPdbPointer (ImageContext.Handle);
|
||||
|
||||
//
|
||||
// Set new rebased address.
|
||||
//
|
||||
NewPe32BaseAddress = XipBase + (UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) \
|
||||
- TEImageHeader->StrippedSize - (UINTN) (*FfsFile);
|
||||
|
||||
//
|
||||
// if reloc is stripped, try to get the original efi image to get reloc info.
|
||||
//
|
||||
if (ImageContext.RelocationsStripped) {
|
||||
//
|
||||
// Construct the original efi file name
|
||||
//
|
||||
if (strlen (FileName) >= MAX_LONG_FILE_PATH) {
|
||||
Error (NULL, 0, 2000, "Invalid", "The file name %s is too long.", FileName);
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
strncpy (PeFileName, FileName, MAX_LONG_FILE_PATH - 1);
|
||||
PeFileName[MAX_LONG_FILE_PATH - 1] = 0;
|
||||
Cptr = PeFileName + strlen (PeFileName);
|
||||
while (*Cptr != '.') {
|
||||
Cptr --;
|
||||
}
|
||||
|
||||
if (*Cptr != '.') {
|
||||
Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);
|
||||
return EFI_ABORTED;
|
||||
} else {
|
||||
*(Cptr + 1) = 'e';
|
||||
*(Cptr + 2) = 'f';
|
||||
*(Cptr + 3) = 'i';
|
||||
*(Cptr + 4) = '\0';
|
||||
}
|
||||
|
||||
PeFile = fopen (LongFilePath (PeFileName), "rb");
|
||||
if (PeFile == NULL) {
|
||||
Warning (NULL, 0, 0, "Invalid", "The file %s has no .reloc section.", FileName);
|
||||
//Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);
|
||||
//return EFI_ABORTED;
|
||||
} else {
|
||||
//
|
||||
// Get the file size
|
||||
//
|
||||
PeFileSize = _filelength (fileno (PeFile));
|
||||
PeFileBuffer = (UINT8 *) malloc (PeFileSize);
|
||||
if (PeFileBuffer == NULL) {
|
||||
fclose (PeFile);
|
||||
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
//
|
||||
// Read Pe File
|
||||
//
|
||||
fread (PeFileBuffer, sizeof (UINT8), PeFileSize, PeFile);
|
||||
//
|
||||
// close file
|
||||
//
|
||||
fclose (PeFile);
|
||||
//
|
||||
// Append reloc section into TeImage
|
||||
//
|
||||
ImageContext.Handle = PeFileBuffer;
|
||||
Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 3000, "Invalid TeImage", "The input file is %s and the return status is %x", FileName, (int) Status);
|
||||
return Status;
|
||||
}
|
||||
ImageContext.RelocationsStripped = FALSE;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Relocation doesn't exist
|
||||
//
|
||||
if (ImageContext.RelocationsStripped) {
|
||||
Warning (NULL, 0, 0, "Invalid", "The file %s has no .reloc section.", FileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Relocation exist and rebase
|
||||
//
|
||||
//
|
||||
// Load and Relocate Image Data
|
||||
//
|
||||
MemoryImagePointer = (UINT8 *) malloc ((UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);
|
||||
if (MemoryImagePointer == NULL) {
|
||||
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);
|
||||
ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~((UINTN) ImageContext.SectionAlignment - 1));
|
||||
|
||||
Status = PeCoffLoaderLoadImage (&ImageContext);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 3000, "Invalid", "LocateImage() call failed on rebase of %s", FileName);
|
||||
free ((VOID *) MemoryImagePointer);
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Reloacate TeImage
|
||||
//
|
||||
ImageContext.DestinationAddress = NewPe32BaseAddress;
|
||||
Status = PeCoffLoaderRelocateImage (&ImageContext);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed on rebase of TE image %s", FileName);
|
||||
free ((VOID *) MemoryImagePointer);
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Copy the relocated image into raw image file.
|
||||
//
|
||||
SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (TEImageHeader + 1);
|
||||
for (Index = 0; Index < TEImageHeader->NumberOfSections; Index ++, SectionHeader ++) {
|
||||
if (!ImageContext.IsTeImage) {
|
||||
CopyMem (
|
||||
(UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData,
|
||||
(VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress),
|
||||
SectionHeader->SizeOfRawData
|
||||
);
|
||||
} else {
|
||||
CopyMem (
|
||||
(UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData,
|
||||
(VOID*) (UINTN) (ImageContext.ImageAddress + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->VirtualAddress),
|
||||
SectionHeader->SizeOfRawData
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Free the allocated memory resource
|
||||
//
|
||||
free ((VOID *) MemoryImagePointer);
|
||||
MemoryImagePointer = NULL;
|
||||
if (PeFileBuffer != NULL) {
|
||||
free (PeFileBuffer);
|
||||
PeFileBuffer = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Update Image Base Address
|
||||
//
|
||||
TEImageHeader->ImageBase = NewPe32BaseAddress;
|
||||
|
||||
//
|
||||
// Now update file checksum
|
||||
//
|
||||
if ((*FfsFile)->Attributes & FFS_ATTRIB_CHECKSUM) {
|
||||
SavedState = (*FfsFile)->State;
|
||||
(*FfsFile)->IntegrityCheck.Checksum.File = 0;
|
||||
(*FfsFile)->State = 0;
|
||||
(*FfsFile)->IntegrityCheck.Checksum.File = CalculateChecksum8 (
|
||||
(UINT8 *)((UINT8 *)(*FfsFile) + FfsHeaderSize),
|
||||
GetFfsFileLength (*FfsFile) - FfsHeaderSize
|
||||
);
|
||||
(*FfsFile)->State = SavedState;
|
||||
}
|
||||
//
|
||||
// Get this module function address from ModulePeMapFile and add them into FvMap file
|
||||
//
|
||||
|
||||
//
|
||||
// Default use FileName as map file path
|
||||
//
|
||||
if (PdbPointer == NULL) {
|
||||
PdbPointer = FileName;
|
||||
}
|
||||
|
||||
WriteMapFile (
|
||||
FvMapFile,
|
||||
PdbPointer,
|
||||
*FfsFile,
|
||||
NewPe32BaseAddress,
|
||||
&OrigImageContext
|
||||
);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ STATIC CHAR8 *mSectionTypeName[] = {
|
|||
NULL, // 0x0F - reserved
|
||||
"EFI_SECTION_PE32", // 0x10
|
||||
"EFI_SECTION_PIC", // 0x11
|
||||
"EFI_SECTION_TE", // 0x12
|
||||
NULL, // 0x12 - formerly TE
|
||||
"EFI_SECTION_DXE_DEPEX", // 0x13
|
||||
"EFI_SECTION_VERSION", // 0x14
|
||||
"EFI_SECTION_USER_INTERFACE", // 0x15
|
||||
|
@ -162,7 +162,7 @@ Returns:
|
|||
fprintf (stdout, " -s [SectionType], --sectiontype [SectionType]\n\
|
||||
SectionType defined in PI spec is one type of\n\
|
||||
EFI_SECTION_COMPRESSION, EFI_SECTION_GUID_DEFINED,\n\
|
||||
EFI_SECTION_PE32, EFI_SECTION_PIC, EFI_SECTION_TE,\n\
|
||||
EFI_SECTION_PE32, EFI_SECTION_PIC,\n\
|
||||
EFI_SECTION_DXE_DEPEX, EFI_SECTION_COMPATIBILITY16,\n\
|
||||
EFI_SECTION_USER_INTERFACE, EFI_SECTION_VERSION,\n\
|
||||
EFI_SECTION_FIRMWARE_VOLUME_IMAGE, EFI_SECTION_RAW,\n\
|
||||
|
@ -438,8 +438,6 @@ Returns:
|
|||
FILE *InFile;
|
||||
EFI_COMMON_SECTION_HEADER *SectHeader;
|
||||
EFI_COMMON_SECTION_HEADER2 TempSectHeader;
|
||||
EFI_TE_IMAGE_HEADER TeHeader;
|
||||
UINT32 TeOffset;
|
||||
EFI_GUID_DEFINED_SECTION GuidSectHeader;
|
||||
EFI_GUID_DEFINED_SECTION2 GuidSectHeader2;
|
||||
UINT32 HeaderSize;
|
||||
|
@ -456,7 +454,6 @@ Returns:
|
|||
|
||||
Size = 0;
|
||||
Offset = 0;
|
||||
TeOffset = 0;
|
||||
//
|
||||
// Go through our array of file names and copy their contents
|
||||
// to the output buffer.
|
||||
|
@ -490,9 +487,8 @@ Returns:
|
|||
//
|
||||
if (InputFileAlign != NULL) {
|
||||
//
|
||||
// Check this section is Te/Pe section, and Calculate the numbers of Te/Pe section.
|
||||
// Check this section is Pe section, and Calculate the numbers of Pe section.
|
||||
//
|
||||
TeOffset = 0;
|
||||
//
|
||||
// The section might be EFI_COMMON_SECTION_HEADER2
|
||||
// But only Type needs to be checked
|
||||
|
@ -503,12 +499,7 @@ Returns:
|
|||
HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER);
|
||||
}
|
||||
fread (&TempSectHeader, 1, HeaderSize, InFile);
|
||||
if (TempSectHeader.Type == EFI_SECTION_TE) {
|
||||
fread (&TeHeader, 1, sizeof (TeHeader), InFile);
|
||||
if (TeHeader.Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
|
||||
TeOffset = TeHeader.StrippedSize - sizeof (TeHeader);
|
||||
}
|
||||
} else if (TempSectHeader.Type == EFI_SECTION_GUID_DEFINED) {
|
||||
if (TempSectHeader.Type == EFI_SECTION_GUID_DEFINED) {
|
||||
fseek (InFile, 0, SEEK_SET);
|
||||
if (FileSize >= MAX_SECTION_SIZE) {
|
||||
fread (&GuidSectHeader2, 1, sizeof (GuidSectHeader2), InFile);
|
||||
|
@ -525,21 +516,12 @@ Returns:
|
|||
|
||||
fseek (InFile, 0, SEEK_SET);
|
||||
|
||||
//
|
||||
// Revert TeOffset to the converse value relative to Alignment
|
||||
// This is to assure the original PeImage Header at Alignment.
|
||||
//
|
||||
if (TeOffset != 0) {
|
||||
TeOffset = InputFileAlign [Index] - (TeOffset % InputFileAlign [Index]);
|
||||
TeOffset = TeOffset % InputFileAlign [Index];
|
||||
}
|
||||
|
||||
//
|
||||
// make sure section data meet its alignment requirement by adding one raw pad section.
|
||||
//
|
||||
if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize + TeOffset) % InputFileAlign [Index]) != 0)) {
|
||||
Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + TeOffset + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1);
|
||||
Offset = Offset - Size - HeaderSize - TeOffset;
|
||||
if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize) % InputFileAlign [Index]) != 0)) {
|
||||
Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1);
|
||||
Offset = Offset - Size - HeaderSize;
|
||||
|
||||
if (FileBuffer != NULL && ((Size + Offset) < *BufferLength)) {
|
||||
//
|
||||
|
@ -1713,8 +1695,6 @@ Returns:
|
|||
SectType = EFI_SECTION_PE32;
|
||||
} else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_PIC]) == 0) {
|
||||
SectType = EFI_SECTION_PIC;
|
||||
} else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_TE]) == 0) {
|
||||
SectType = EFI_SECTION_TE;
|
||||
} else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_DXE_DEPEX]) == 0) {
|
||||
SectType = EFI_SECTION_DXE_DEPEX;
|
||||
} else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_SMM_DEPEX]) == 0) {
|
||||
|
|
|
@ -665,7 +665,7 @@ Returns:
|
|||
//
|
||||
// 0x12
|
||||
//
|
||||
"EFI_SECTION_TE",
|
||||
"Unsupported section type - formerly TE",
|
||||
//
|
||||
// 0x13
|
||||
//
|
||||
|
@ -1788,7 +1788,6 @@ Returns:
|
|||
switch (Type) {
|
||||
case EFI_SECTION_RAW:
|
||||
case EFI_SECTION_PIC:
|
||||
case EFI_SECTION_TE:
|
||||
// default is no more information
|
||||
break;
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ BINARY_FILE_TYPE_PIC = 'PIC'
|
|||
BINARY_FILE_TYPE_PEI_DEPEX = 'PEI_DEPEX'
|
||||
BINARY_FILE_TYPE_DXE_DEPEX = 'DXE_DEPEX'
|
||||
BINARY_FILE_TYPE_SMM_DEPEX = 'SMM_DEPEX'
|
||||
BINARY_FILE_TYPE_TE = 'TE'
|
||||
BINARY_FILE_TYPE_VER = 'VER'
|
||||
BINARY_FILE_TYPE_UI = 'UI'
|
||||
BINARY_FILE_TYPE_BIN = 'BIN'
|
||||
|
|
|
@ -17,7 +17,6 @@ SectionHeaderType = {
|
|||
0x03:'EFI_SECTION_DISPOSABLE',
|
||||
0x10:'EFI_SECTION_PE32',
|
||||
0x11:'EFI_SECTION_PIC',
|
||||
0x12:'EFI_SECTION_TE',
|
||||
0x13:'EFI_SECTION_DXE_DEPEX',
|
||||
0x14:'EFI_SECTION_VERSION',
|
||||
0x15:'EFI_SECTION_USER_INTERFACE',
|
||||
|
|
|
@ -79,10 +79,10 @@ class DataSection (DataSectionClassObject):
|
|||
CopyLongFilePath(MapFile, CopyMapFile)
|
||||
|
||||
#Get PE Section alignment when align is set to AUTO
|
||||
if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
|
||||
if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_PE32):
|
||||
self.Alignment = "0"
|
||||
NoStrip = True
|
||||
if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
|
||||
if self.SecType in (BINARY_FILE_TYPE_PE32):
|
||||
if self.KeepReloc is not None:
|
||||
NoStrip = self.KeepReloc
|
||||
|
||||
|
@ -100,16 +100,6 @@ class DataSection (DataSectionClassObject):
|
|||
)
|
||||
self.SectFileName = StrippedFile
|
||||
|
||||
if self.SecType == BINARY_FILE_TYPE_TE:
|
||||
TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
|
||||
GenFdsGlobalVariable.GenerateFirmwareImage(
|
||||
TeFile,
|
||||
[GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
|
||||
Type='te',
|
||||
IsMakefile = IsMakefile
|
||||
)
|
||||
self.SectFileName = TeFile
|
||||
|
||||
OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get(self.SecType))
|
||||
OutputFile = os.path.normpath(OutputFile)
|
||||
GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)
|
||||
|
|
|
@ -62,7 +62,7 @@ class EfiSection (EfiSectionClassObject):
|
|||
StringData = FfsInf.__ExtendMacro__(self.StringData)
|
||||
ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)')
|
||||
NoStrip = True
|
||||
if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_MM_CORE_STANDALONE) and SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
|
||||
if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_MM_CORE_STANDALONE) and SectionType in (BINARY_FILE_TYPE_PE32):
|
||||
if FfsInf.KeepReloc is not None:
|
||||
NoStrip = FfsInf.KeepReloc
|
||||
elif FfsInf.KeepRelocFromRule is not None:
|
||||
|
@ -259,7 +259,7 @@ class EfiSection (EfiSectionClassObject):
|
|||
File = GenFdsGlobalVariable.MacroExtend(File, Dict)
|
||||
|
||||
#Get PE Section alignment when align is set to AUTO
|
||||
if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
|
||||
if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32):
|
||||
Align = "0"
|
||||
if File[(len(File)-4):] == '.efi' and FfsInf.InfModule.BaseName == os.path.basename(File)[:-4]:
|
||||
MapFile = File.replace('.efi', '.map')
|
||||
|
@ -295,18 +295,6 @@ class EfiSection (EfiSectionClassObject):
|
|||
)
|
||||
File = StrippedFile
|
||||
|
||||
"""For TE Section call GenFw to generate TE image"""
|
||||
|
||||
if SectionType == BINARY_FILE_TYPE_TE:
|
||||
TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
|
||||
GenFdsGlobalVariable.GenerateFirmwareImage(
|
||||
TeFile,
|
||||
[File],
|
||||
Type='te',
|
||||
IsMakefile = IsMakefile
|
||||
)
|
||||
File = TeFile
|
||||
|
||||
"""Call GenSection"""
|
||||
GenFdsGlobalVariable.GenerateSection(OutputFile,
|
||||
[File],
|
||||
|
|
|
@ -2597,7 +2597,7 @@ class FdfParser:
|
|||
#
|
||||
@staticmethod
|
||||
def _SectionCouldHaveRelocFlag (SectionType):
|
||||
if SectionType in {BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32}:
|
||||
if SectionType in {BINARY_FILE_TYPE_PE32}:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -2806,7 +2806,7 @@ class FdfParser:
|
|||
|
||||
if self._IsKeyword("VERSION"):
|
||||
if AlignValue == 'Auto':
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
if not self._IsToken(TAB_EQUAL_SPLIT):
|
||||
raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber)
|
||||
if not self._GetNextToken():
|
||||
|
@ -2822,7 +2822,7 @@ class FdfParser:
|
|||
|
||||
elif self._IsKeyword(BINARY_FILE_TYPE_UI):
|
||||
if AlignValue == 'Auto':
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
if not self._IsToken(TAB_EQUAL_SPLIT):
|
||||
raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber)
|
||||
if not self._GetNextToken():
|
||||
|
@ -2837,7 +2837,7 @@ class FdfParser:
|
|||
|
||||
elif self._IsKeyword("FV_IMAGE"):
|
||||
if AlignValue == 'Auto':
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
if not self._IsToken(TAB_EQUAL_SPLIT):
|
||||
raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber)
|
||||
if not self._GetNextToken():
|
||||
|
@ -2878,7 +2878,7 @@ class FdfParser:
|
|||
|
||||
elif self._IsKeyword("PEI_DEPEX_EXP") or self._IsKeyword("DXE_DEPEX_EXP") or self._IsKeyword("SMM_DEPEX_EXP"):
|
||||
if AlignValue == 'Auto':
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
DepexSectionObj = DepexSection()
|
||||
DepexSectionObj.Alignment = AlignValue
|
||||
DepexSectionObj.DepexType = self._Token
|
||||
|
@ -2895,7 +2895,7 @@ class FdfParser:
|
|||
|
||||
elif self._IsKeyword("SUBTYPE_GUID"):
|
||||
if AlignValue == 'Auto':
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
SubTypeGuidValue = None
|
||||
if not self._GetNextGuid():
|
||||
raise Warning.Expected("GUID", self.FileName, self.CurrentLineNumber)
|
||||
|
@ -2923,11 +2923,11 @@ class FdfParser:
|
|||
self.SetFileBufferPos(OldPos)
|
||||
return False
|
||||
|
||||
if self._Token not in {"COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
|
||||
if self._Token not in {"COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
|
||||
BINARY_FILE_TYPE_UI, "VERSION", BINARY_FILE_TYPE_PEI_DEPEX, "SUBTYPE_GUID", BINARY_FILE_TYPE_SMM_DEPEX}:
|
||||
raise Warning("Unknown section type '%s'" % self._Token, self.FileName, self.CurrentLineNumber)
|
||||
if AlignValue == 'Auto'and (not self._Token == BINARY_FILE_TYPE_PE32) and (not self._Token == BINARY_FILE_TYPE_TE):
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
if AlignValue == 'Auto'and (not self._Token == BINARY_FILE_TYPE_PE32):
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
|
||||
# DataSection
|
||||
DataSectionObj = DataSection()
|
||||
|
@ -3726,7 +3726,7 @@ class FdfParser:
|
|||
|
||||
if SectionName not in {
|
||||
"COMPAT16", BINARY_FILE_TYPE_PE32,
|
||||
BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE",
|
||||
BINARY_FILE_TYPE_PIC, "FV_IMAGE",
|
||||
"RAW",BINARY_FILE_TYPE_DXE_DEPEX, BINARY_FILE_TYPE_UI,
|
||||
BINARY_FILE_TYPE_PEI_DEPEX, "VERSION", "SUBTYPE_GUID",
|
||||
BINARY_FILE_TYPE_SMM_DEPEX}:
|
||||
|
@ -3743,8 +3743,8 @@ class FdfParser:
|
|||
if self._GetAlignment():
|
||||
if self._Token not in ALIGNMENTS:
|
||||
raise Warning("Incorrect alignment '%s'" % self._Token, self.FileName, self.CurrentLineNumber)
|
||||
if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32):
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
SectAlignment = self._Token
|
||||
|
||||
Ext = None
|
||||
|
@ -3796,7 +3796,7 @@ class FdfParser:
|
|||
|
||||
if SectionName not in {
|
||||
"COMPAT16", BINARY_FILE_TYPE_PE32,
|
||||
BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE",
|
||||
BINARY_FILE_TYPE_PIC, "FV_IMAGE",
|
||||
"RAW",BINARY_FILE_TYPE_DXE_DEPEX, BINARY_FILE_TYPE_UI,
|
||||
BINARY_FILE_TYPE_PEI_DEPEX, "VERSION", "SUBTYPE_GUID",
|
||||
BINARY_FILE_TYPE_SMM_DEPEX, BINARY_FILE_TYPE_GUID}:
|
||||
|
@ -3843,7 +3843,7 @@ class FdfParser:
|
|||
elif self._GetNextToken():
|
||||
if self._Token not in {
|
||||
T_CHAR_BRACE_R, "COMPAT16", BINARY_FILE_TYPE_PE32,
|
||||
BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE,
|
||||
BINARY_FILE_TYPE_PIC,
|
||||
"FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,
|
||||
BINARY_FILE_TYPE_UI, "VERSION",
|
||||
BINARY_FILE_TYPE_PEI_DEPEX, BINARY_FILE_TYPE_GUID,
|
||||
|
@ -3907,8 +3907,8 @@ class FdfParser:
|
|||
if self._GetAlignment():
|
||||
if self._Token not in ALIGNMENTS:
|
||||
raise Warning("Incorrect alignment '%s'" % self._Token, self.FileName, self.CurrentLineNumber)
|
||||
if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32):
|
||||
raise Warning("Auto alignment can only be used in PE32 section ", self.FileName, self.CurrentLineNumber)
|
||||
EfiSectionObj.Alignment = self._Token
|
||||
|
||||
if self._IsKeyword('RELOCS_STRIPPED') or self._IsKeyword('RELOCS_RETAINED'):
|
||||
|
@ -3928,7 +3928,7 @@ class FdfParser:
|
|||
elif self._GetNextToken():
|
||||
if self._Token not in {
|
||||
T_CHAR_BRACE_R, "COMPAT16", BINARY_FILE_TYPE_PE32,
|
||||
BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE,
|
||||
BINARY_FILE_TYPE_PIC,
|
||||
"FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,
|
||||
BINARY_FILE_TYPE_UI, "VERSION",
|
||||
BINARY_FILE_TYPE_PEI_DEPEX, BINARY_FILE_TYPE_GUID,
|
||||
|
@ -4020,9 +4020,6 @@ class FdfParser:
|
|||
elif SectionType == BINARY_FILE_TYPE_PIC:
|
||||
if FileType not in {BINARY_FILE_TYPE_PIC, "SEC_PIC"}:
|
||||
raise Warning(WarningString % FileType, self.FileName, self.CurrentLineNumber)
|
||||
elif SectionType == BINARY_FILE_TYPE_TE:
|
||||
if FileType not in {BINARY_FILE_TYPE_TE, "SEC_TE"}:
|
||||
raise Warning(WarningString % FileType, self.FileName, self.CurrentLineNumber)
|
||||
elif SectionType == "RAW":
|
||||
if FileType not in {BINARY_FILE_TYPE_BIN, "SEC_BIN", "RAW", "ASL", "ACPI"}:
|
||||
raise Warning(WarningString % FileType, self.FileName, self.CurrentLineNumber)
|
||||
|
|
|
@ -33,7 +33,6 @@ FdfFvFileTypeToFileType = {
|
|||
SectionSuffix = {
|
||||
BINARY_FILE_TYPE_PE32 : '.pe32',
|
||||
BINARY_FILE_TYPE_PIC : '.pic',
|
||||
BINARY_FILE_TYPE_TE : '.te',
|
||||
BINARY_FILE_TYPE_DXE_DEPEX : '.dpx',
|
||||
'VERSION' : '.ver',
|
||||
BINARY_FILE_TYPE_UI : '.ui',
|
||||
|
|
|
@ -769,7 +769,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
|||
File = GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)
|
||||
|
||||
#Get PE Section alignment when align is set to AUTO
|
||||
if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
|
||||
if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32):
|
||||
ImageObj = PeImageClass (File)
|
||||
if ImageObj.SectionAlignment < 0x400:
|
||||
self.Alignment = str (ImageObj.SectionAlignment)
|
||||
|
@ -792,15 +792,6 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
|||
)
|
||||
File = StrippedFile
|
||||
|
||||
if SectionType == BINARY_FILE_TYPE_TE:
|
||||
TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')
|
||||
GenFdsGlobalVariable.GenerateFirmwareImage(
|
||||
TeFile,
|
||||
[File],
|
||||
Type='te',
|
||||
IsMakefile=IsMakefile
|
||||
)
|
||||
File = TeFile
|
||||
GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType], IsMakefile=IsMakefile)
|
||||
OutputFileList.append(OutputFile)
|
||||
else:
|
||||
|
@ -811,7 +802,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
|||
GenSecInputFile = GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)
|
||||
|
||||
#Get PE Section alignment when align is set to AUTO
|
||||
if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
|
||||
if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32):
|
||||
ImageObj = PeImageClass (GenSecInputFile)
|
||||
if ImageObj.SectionAlignment < 0x400:
|
||||
self.Alignment = str (ImageObj.SectionAlignment)
|
||||
|
@ -835,15 +826,6 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
|||
)
|
||||
GenSecInputFile = StrippedFile
|
||||
|
||||
if SectionType == BINARY_FILE_TYPE_TE:
|
||||
TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')
|
||||
GenFdsGlobalVariable.GenerateFirmwareImage(
|
||||
TeFile,
|
||||
[GenSecInputFile],
|
||||
Type='te',
|
||||
IsMakefile=IsMakefile
|
||||
)
|
||||
GenSecInputFile = TeFile
|
||||
GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType], IsMakefile=IsMakefile)
|
||||
OutputFileList.append(OutputFile)
|
||||
|
||||
|
|
|
@ -733,12 +733,12 @@ class GenFds(object):
|
|||
if not os.path.exists(FfsPath[0]):
|
||||
continue
|
||||
MatchDict = {}
|
||||
ReFileEnds = compile('\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$')
|
||||
ReFileEnds = compile('\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$')
|
||||
FileList = os.listdir(FfsPath[0])
|
||||
for File in FileList:
|
||||
Match = ReFileEnds.search(File)
|
||||
if Match:
|
||||
for Index in range(1, 8):
|
||||
for Index in range(1, 7):
|
||||
if Match.group(Index) and Match.group(Index) in MatchDict:
|
||||
MatchDict[Match.group(Index)].append(File)
|
||||
elif Match.group(Index):
|
||||
|
@ -759,8 +759,6 @@ class GenFds(object):
|
|||
FileList = MatchDict['fv.sec.txt']
|
||||
elif '.pe32.txt' in MatchDict:
|
||||
FileList = MatchDict['.pe32.txt']
|
||||
elif '.te.txt' in MatchDict:
|
||||
FileList = MatchDict['.te.txt']
|
||||
elif '.pic.txt' in MatchDict:
|
||||
FileList = MatchDict['.pic.txt']
|
||||
elif '.raw.txt' in MatchDict:
|
||||
|
|
|
@ -26,7 +26,6 @@ class Section (SectionClassObject):
|
|||
'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID',
|
||||
BINARY_FILE_TYPE_PE32 : 'EFI_SECTION_PE32',
|
||||
BINARY_FILE_TYPE_PIC : 'EFI_SECTION_PIC',
|
||||
BINARY_FILE_TYPE_TE : 'EFI_SECTION_TE',
|
||||
'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',
|
||||
'COMPAT16' : 'EFI_SECTION_COMPATIBILITY16',
|
||||
BINARY_FILE_TYPE_DXE_DEPEX : 'EFI_SECTION_DXE_DEPEX',
|
||||
|
@ -47,7 +46,6 @@ class Section (SectionClassObject):
|
|||
BINARY_FILE_TYPE_PIC : '.pic',
|
||||
BINARY_FILE_TYPE_PEI_DEPEX : '.depex',
|
||||
'SEC_PEI_DEPEX' : '.depex',
|
||||
BINARY_FILE_TYPE_TE : '.te',
|
||||
BINARY_FILE_TYPE_UNI_VER : '.ver',
|
||||
BINARY_FILE_TYPE_VER : '.ver',
|
||||
BINARY_FILE_TYPE_UNI_UI : '.ui',
|
||||
|
@ -62,7 +60,6 @@ class Section (SectionClassObject):
|
|||
'SEC_GUID' : '.sec' ,
|
||||
'SEC_PE32' : '.sec' ,
|
||||
'SEC_PIC' : '.sec',
|
||||
'SEC_TE' : '.sec',
|
||||
'SEC_VER' : '.sec',
|
||||
'SEC_UI' : '.sec',
|
||||
'SEC_COMPAT16' : '.sec',
|
||||
|
@ -124,8 +121,7 @@ class Section (SectionClassObject):
|
|||
for File in FfsInf.BinFileList:
|
||||
if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch:
|
||||
if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \
|
||||
and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \
|
||||
or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32):
|
||||
and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX):
|
||||
if TAB_STAR in FfsInf.TargetOverrideList or File.Target == TAB_STAR or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []:
|
||||
FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type))
|
||||
else:
|
||||
|
|
|
@ -424,7 +424,6 @@ BINARY_FILE_TYPE_PIC = 'PIC'
|
|||
BINARY_FILE_TYPE_PEI_DEPEX = 'PEI_DEPEX'
|
||||
BINARY_FILE_TYPE_DXE_DEPEX = 'DXE_DEPEX'
|
||||
BINARY_FILE_TYPE_SMM_DEPEX = 'SMM_DEPEX'
|
||||
BINARY_FILE_TYPE_TE = 'TE'
|
||||
BINARY_FILE_TYPE_VER = 'VER'
|
||||
BINARY_FILE_TYPE_UI = 'UI'
|
||||
BINARY_FILE_TYPE_BIN = 'BIN'
|
||||
|
|
|
@ -175,13 +175,13 @@ COMPAT16\cell \hich\af4\dbch\af31505\loch\f4 EFI_SECTION_COMPATIBILITY16\cell }\
|
|||
\ltrch\fcs0 \fs18\cf1\insrsid15798865\charrsid12198464 \hich\af43\dbch\af31505\loch\f43 If no options ar}{\rtlch\fcs1 \af43\afs18 \ltrch\fcs0 \fs18\cf1\insrsid15798865 \hich\af43\dbch\af31505\loch\f43 e specified, tool prints usage.}{\rtlch\fcs1
|
||||
\ab\af43\afs18 \ltrch\fcs0 \b\fs18\cf1\insrsid13127309
|
||||
\par }{\rtlch\fcs1 \ab\af43\afs18 \ltrch\fcs0 \b\fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 Filename1 [FilenameN]
|
||||
\par }\pard \ltrpar\ql \li360\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af43\afs18 \ltrch\fcs0 \fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 Input PE/PE32+ image, or TE image, or other binary files.
|
||||
\par }\pard \ltrpar\ql \li360\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af43\afs18 \ltrch\fcs0 \fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 Input PE/PE32+ image or other binary files.
|
||||
\par }\pard \ltrpar\ql \li0\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \ab\af43\afs18 \ltrch\fcs0 \b\fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 -o FileName, --outputfile FileName
|
||||
\par }\pard \ltrpar\ql \li360\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af43\afs18 \ltrch\fcs0 \fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 The PI section file is created. This option is required.
|
||||
\par }\pard \ltrpar\ql \li0\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \ab\af43\afs18 \ltrch\fcs0 \b\fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 -s SectionType, --sectiontype SectionType
|
||||
\par }\pard \ltrpar\ql \li360\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af43\afs18 \ltrch\fcs0 \fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 SectionType defined in PI spec is one type of EFI_SECTION_COMPRE
|
||||
\hich\af43\dbch\af31505\loch\f43
|
||||
SSION, EFI_SECTION_GUID_DEFINED, EFI_SECTION_PE32, EFI_SECTION_PIC, EFI_SECTION_TE, EFI_SECTION_DXE_DEPEX, EFI_SECTION_COMPATIBILITY16, EFI_SECTION_USER_INTERFACE, EFI_SECTION_VERSION, EFI_SECTION_FIRMWARE_VOLUME_IMAGE, EFI_SECTION_RAW, EFI_SECTION_FREEFO
|
||||
SSION, EFI_SECTION_GUID_DEFINED, EFI_SECTION_PE32, EFI_SECTION_PIC, EFI_SECTION_DXE_DEPEX, EFI_SECTION_COMPATIBILITY16, EFI_SECTION_USER_INTERFACE, EFI_SECTION_VERSION, EFI_SECTION_FIRMWARE_VOLUME_IMAGE, EFI_SECTION_RAW, EFI_SECTION_FREEFO
|
||||
\hich\af43\dbch\af31505\loch\f43 R\hich\af43\dbch\af31505\loch\f43 M_SUBTYPE_GUID, EFI_SECTION_PEI_DEPEX. If sectiontype is not given, EFI_SECTION_ALL is default type to contain the input all sections to one section file.
|
||||
\par }\pard \ltrpar\ql \li0\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \ab\af43\afs18 \ltrch\fcs0 \b\fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 -c [Type], --compress [Type]
|
||||
\par }\pard \ltrpar\ql \li360\ri0\sb200\nowidctlpar\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af43\afs18 \ltrch\fcs0 \fs18\cf1\insrsid11342878 \hich\af43\dbch\af31505\loch\f43 Compress method type can be PI_NONE, PI_STD or TIANO. If Type is not given, PI_
|
||||
|
|
|
@ -112,14 +112,7 @@ ProcessFvSection:
|
|||
)
|
||||
else
|
||||
(
|
||||
if §iontype==0x12 ; TE
|
||||
(
|
||||
do EfiProcessTeImage (&secstart+0x4)
|
||||
)
|
||||
else
|
||||
(
|
||||
print "unknown section type"
|
||||
)
|
||||
print "unknown section type"
|
||||
)
|
||||
|
||||
return
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
;
|
||||
; Copyright (c) 2011, Hewlett-Packard Company. All rights reserved.<BR>
|
||||
;
|
||||
; SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
;
|
||||
|
||||
LOCAL &imgstart &strippedsize &debugdirentryrva &debugtype &debugrva &dwarfsig &elfbase &elfpath &pathoffset
|
||||
ENTRY &imgstart
|
||||
|
||||
&imgstart=&imgstart
|
||||
print "TE image found at &imgstart"
|
||||
|
||||
; determine pe header bytes removed to account for in rva references
|
||||
&strippedsize=(Data.Long(a:&imgstart+0x4)&0xffff0000)>>16.
|
||||
&strippedsize=&strippedsize-0x28
|
||||
|
||||
&debugdirentryrva=Data.Long(a:&imgstart+0x20)
|
||||
if &debugdirentryrva==0
|
||||
(
|
||||
print "no debug dir for image at &imgstart"
|
||||
enddo
|
||||
)
|
||||
&debugdirentryrva=&debugdirentryrva-&strippedsize
|
||||
|
||||
&debugtype=Data.Long(a:&imgstart+&debugdirentryrva+0xc)
|
||||
if (&debugtype!=0xdf)&&(&debugtype!=0x02)
|
||||
(
|
||||
print "debug type is not dwarf for image at &imgstart, it's &debugtype"
|
||||
enddo
|
||||
)
|
||||
|
||||
&debugrva=Data.Long(a:&imgstart+&debugdirentryrva+0x14)
|
||||
&debugrva=&debugrva-&strippedsize;
|
||||
&dwarfsig=Data.Long(a:&imgstart+&debugrva);
|
||||
if &dwarfsig==0x66727764
|
||||
(
|
||||
&pathoffset=0xc
|
||||
)
|
||||
else
|
||||
(
|
||||
if &dwarfsig==0x3031424E
|
||||
(
|
||||
&pathoffset=0x10
|
||||
)
|
||||
else
|
||||
(
|
||||
print "debug signature not found for image at &imgstart, its &dwarfsig"
|
||||
enddo
|
||||
)
|
||||
)
|
||||
|
||||
&elfpath=Data.String(c:&imgstart+&debugrva+&pathoffset)
|
||||
|
||||
; elf base is baseofcode (we hope that for TE images it's not baseofdata)
|
||||
&elfbase=&imgstart+Data.Long(a:&imgstart+0xc)-&strippedsize
|
||||
|
||||
print "found path &elfpath"
|
||||
; $fprintf 50, "load /ni /np /a %s &0x%x\n",elfpath,elfbase$;
|
||||
ON ERROR GOSUB
|
||||
return
|
||||
data.load.elf &elfpath &elfbase /NOCODE /NOCLEAR
|
||||
ON error
|
||||
|
||||
enddo
|
|
@ -210,7 +210,6 @@
|
|||
|
||||
[PcdsFeatureFlag]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst|FALSE
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables|FALSE
|
||||
|
||||
[PcdsFixedAtBuild]
|
||||
|
|
|
@ -419,7 +419,6 @@ class EFI_SECTION_TYPE:
|
|||
DISPOSABLE = 0x03
|
||||
PE32 = 0x10
|
||||
PIC = 0x11
|
||||
TE = 0x12
|
||||
DXE_DEPEX = 0x13
|
||||
VERSION = 0x14
|
||||
USER_INTERFACE = 0x15
|
||||
|
|
|
@ -145,20 +145,6 @@ class EFI_IMAGE_DATA_DIRECTORY(Structure):
|
|||
('Size', c_uint32)
|
||||
]
|
||||
|
||||
class EFI_TE_IMAGE_HEADER(Structure):
|
||||
_fields_ = [
|
||||
('Signature', ARRAY(c_char, 2)),
|
||||
('Machine', c_uint16),
|
||||
('NumberOfSections', c_uint8),
|
||||
('Subsystem', c_uint8),
|
||||
('StrippedSize', c_uint16),
|
||||
('AddressOfEntryPoint', c_uint32),
|
||||
('BaseOfCode', c_uint32),
|
||||
('ImageBase', c_uint64),
|
||||
('DataDirectoryBaseReloc', EFI_IMAGE_DATA_DIRECTORY),
|
||||
('DataDirectoryDebug', EFI_IMAGE_DATA_DIRECTORY)
|
||||
]
|
||||
|
||||
class EFI_IMAGE_DOS_HEADER(Structure):
|
||||
_fields_ = [
|
||||
('e_magic', c_uint16),
|
||||
|
@ -326,7 +312,6 @@ class EFI_SECTION_TYPE:
|
|||
DISPOSABLE = 0x03
|
||||
PE32 = 0x10
|
||||
PIC = 0x11
|
||||
TE = 0x12
|
||||
DXE_DEPEX = 0x13
|
||||
VERSION = 0x14
|
||||
USER_INTERFACE = 0x15
|
||||
|
@ -633,11 +618,8 @@ class FirmwareDevice:
|
|||
class PeTeImage:
|
||||
def __init__(self, offset, data):
|
||||
self.Offset = offset
|
||||
tehdr = EFI_TE_IMAGE_HEADER.from_buffer (data, 0)
|
||||
if tehdr.Signature == b'VZ': # TE image
|
||||
self.TeHdr = tehdr
|
||||
elif tehdr.Signature == b'MZ': # PE image
|
||||
self.TeHdr = None
|
||||
doshdr = EFI_IMAGE_DOS_HEADER.from_buffer (data, 0)
|
||||
elif doshdr.e_magic == b'MZ': # PE image
|
||||
self.DosHdr = EFI_IMAGE_DOS_HEADER.from_buffer (data, 0)
|
||||
self.PeHdr = EFI_IMAGE_NT_HEADERS32.from_buffer (data, self.DosHdr.e_lfanew)
|
||||
if self.PeHdr.Signature != 0x4550:
|
||||
|
@ -658,20 +640,13 @@ class PeTeImage:
|
|||
self.Data = data
|
||||
self.RelocList = []
|
||||
|
||||
def IsTeImage(self):
|
||||
return self.TeHdr is not None
|
||||
|
||||
def ParseReloc(self):
|
||||
if self.IsTeImage():
|
||||
rsize = self.TeHdr.DataDirectoryBaseReloc.Size
|
||||
roffset = sizeof(self.TeHdr) - self.TeHdr.StrippedSize + self.TeHdr.DataDirectoryBaseReloc.VirtualAddress
|
||||
else:
|
||||
# Assuming PE32 image type (self.PeHdr.OptionalHeader.PeOptHdr.Magic == 0x10b)
|
||||
rsize = self.PeHdr.OptionalHeader.PeOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].Size
|
||||
roffset = self.PeHdr.OptionalHeader.PeOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].VirtualAddress
|
||||
if self.PeHdr.OptionalHeader.PePlusOptHdr.Magic == 0x20b: # PE32+ image
|
||||
rsize = self.PeHdr.OptionalHeader.PePlusOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].Size
|
||||
roffset = self.PeHdr.OptionalHeader.PePlusOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].VirtualAddress
|
||||
# Assuming PE32 image type (self.PeHdr.OptionalHeader.PeOptHdr.Magic == 0x10b)
|
||||
rsize = self.PeHdr.OptionalHeader.PeOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].Size
|
||||
roffset = self.PeHdr.OptionalHeader.PeOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].VirtualAddress
|
||||
if self.PeHdr.OptionalHeader.PePlusOptHdr.Magic == 0x20b: # PE32+ image
|
||||
rsize = self.PeHdr.OptionalHeader.PePlusOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].Size
|
||||
roffset = self.PeHdr.OptionalHeader.PePlusOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].VirtualAddress
|
||||
|
||||
alignment = 4
|
||||
offset = roffset
|
||||
|
@ -692,8 +667,6 @@ class PeTeImage:
|
|||
raise Exception("ERROR: Unsupported relocation type %d!" % rtype)
|
||||
# Calculate the offset of the relocation
|
||||
aoff = blkhdr.PageRVA + roff
|
||||
if self.IsTeImage():
|
||||
aoff += sizeof(self.TeHdr) - self.TeHdr.StrippedSize
|
||||
self.RelocList.append((rtype, aoff))
|
||||
offset += sizeof(rdata)
|
||||
|
||||
|
@ -718,18 +691,14 @@ class PeTeImage:
|
|||
else:
|
||||
raise Exception('ERROR: Unknown relocation type %d !' % rtype)
|
||||
|
||||
if self.IsTeImage():
|
||||
offset = self.Offset + EFI_TE_IMAGE_HEADER.ImageBase.offset
|
||||
size = EFI_TE_IMAGE_HEADER.ImageBase.size
|
||||
offset = self.Offset + self.DosHdr.e_lfanew
|
||||
offset += EFI_IMAGE_NT_HEADERS32.OptionalHeader.offset
|
||||
if self.PeHdr.OptionalHeader.PePlusOptHdr.Magic == 0x20b: # PE32+ image
|
||||
offset += EFI_IMAGE_OPTIONAL_HEADER32_PLUS.ImageBase.offset
|
||||
size = EFI_IMAGE_OPTIONAL_HEADER32_PLUS.ImageBase.size
|
||||
else:
|
||||
offset = self.Offset + self.DosHdr.e_lfanew
|
||||
offset += EFI_IMAGE_NT_HEADERS32.OptionalHeader.offset
|
||||
if self.PeHdr.OptionalHeader.PePlusOptHdr.Magic == 0x20b: # PE32+ image
|
||||
offset += EFI_IMAGE_OPTIONAL_HEADER32_PLUS.ImageBase.offset
|
||||
size = EFI_IMAGE_OPTIONAL_HEADER32_PLUS.ImageBase.size
|
||||
else:
|
||||
offset += EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.offset
|
||||
size = EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.size
|
||||
offset += EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.offset
|
||||
size = EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.size
|
||||
|
||||
value = Bytes2Val(fdbin[offset:offset+size]) + delta
|
||||
fdbin[offset:offset+size] = Val2Bytes(value, size)
|
||||
|
@ -815,7 +784,7 @@ def SplitFspBin (fspfile, outdir, nametemplate):
|
|||
def GetImageFromFv (fd, parentfvoffset, fv, imglist):
|
||||
for ffs in fv.FfsList:
|
||||
for sec in ffs.SecList:
|
||||
if sec.SecHdr.Type in [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]: # TE or PE32
|
||||
if sec.SecHdr.Type in [EFI_SECTION_TYPE.PE32]: # PE32
|
||||
offset = fd.Offset + parentfvoffset + fv.Offset + ffs.Offset + sec.Offset + sizeof(sec.SecHdr)
|
||||
imglist.append ((offset, len(sec.SecData) - sizeof(sec.SecHdr)))
|
||||
|
||||
|
|
|
@ -394,47 +394,22 @@ PeiGetPe32Data (
|
|||
OUT UINT32 *Pe32DataSize
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_SECTION_TYPE SearchType1;
|
||||
EFI_SECTION_TYPE SearchType2;
|
||||
UINT32 AuthenticationState;
|
||||
EFI_STATUS Status;
|
||||
UINT32 AuthenticationState;
|
||||
|
||||
*Pe32Data = NULL;
|
||||
|
||||
if (FeaturePcdGet (PcdPeiCoreImageLoaderSearchTeSectionFirst)) {
|
||||
SearchType1 = EFI_SECTION_TE;
|
||||
SearchType2 = EFI_SECTION_PE32;
|
||||
} else {
|
||||
SearchType1 = EFI_SECTION_PE32;
|
||||
SearchType2 = EFI_SECTION_TE;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to find a first exe section (if PcdPeiCoreImageLoaderSearchTeSectionFirst
|
||||
// is true, TE will be searched first).
|
||||
// Try to find the exe section.
|
||||
//
|
||||
Status = PeiServicesFfsFindSectionData4 (
|
||||
SearchType1,
|
||||
EFI_SECTION_PE32,
|
||||
0,
|
||||
FileHandle,
|
||||
Pe32Data,
|
||||
Pe32DataSize,
|
||||
&AuthenticationState
|
||||
);
|
||||
//
|
||||
// If we didn't find a first exe section, try to find the second exe section.
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = PeiServicesFfsFindSectionData4 (
|
||||
SearchType2,
|
||||
0,
|
||||
FileHandle,
|
||||
Pe32Data,
|
||||
Pe32DataSize,
|
||||
&AuthenticationState
|
||||
);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -472,52 +447,28 @@ PeiLoadImageLoadImage (
|
|||
VOID *Pe32Data;
|
||||
UINT32 Pe32DataSize;
|
||||
EFI_PHYSICAL_ADDRESS ImageAddress;
|
||||
EFI_SECTION_TYPE SearchType1;
|
||||
EFI_SECTION_TYPE SearchType2;
|
||||
UEFI_IMAGE_LOADER_IMAGE_CONTEXT ImageContext;
|
||||
|
||||
*EntryPoint = 0;
|
||||
*AuthenticationState = 0;
|
||||
|
||||
if (FeaturePcdGet (PcdPeiCoreImageLoaderSearchTeSectionFirst)) {
|
||||
SearchType1 = EFI_SECTION_TE;
|
||||
SearchType2 = EFI_SECTION_PE32;
|
||||
} else {
|
||||
SearchType1 = EFI_SECTION_PE32;
|
||||
SearchType2 = EFI_SECTION_TE;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to find a first exe section (if PcdPeiCoreImageLoaderSearchTeSectionFirst
|
||||
// is true, TE will be searched first).
|
||||
// Try to find the exe section.
|
||||
//
|
||||
Status = PeiServicesFfsFindSectionData4 (
|
||||
SearchType1,
|
||||
EFI_SECTION_PE32,
|
||||
0,
|
||||
FileHandle,
|
||||
&Pe32Data,
|
||||
&Pe32DataSize,
|
||||
AuthenticationState
|
||||
);
|
||||
//
|
||||
// If we didn't find a first exe section, try to find the second exe section.
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = PeiServicesFfsFindSectionData4 (
|
||||
SearchType2,
|
||||
0,
|
||||
FileHandle,
|
||||
&Pe32Data,
|
||||
&Pe32DataSize,
|
||||
AuthenticationState
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// PEI core only carry the loader function for TE and PE32 executables
|
||||
// If this two section does not exist, just return.
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// PEI core only carry the loader function for PE32 executables
|
||||
// If this two section does not exist, just return.
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "Loading PEIM %g\n", FileHandle));
|
||||
|
@ -625,7 +576,7 @@ PeiLoadImageLoadImageWrapper (
|
|||
/**
|
||||
Check whether the input image has the relocation.
|
||||
|
||||
@param Pe32Data Pointer to the PE/COFF or TE image.
|
||||
@param Pe32Data Pointer to the PE/COFF image.
|
||||
|
||||
@retval TRUE Relocation is stripped.
|
||||
@retval FALSE Relocation is not stripped.
|
||||
|
@ -665,13 +616,7 @@ RelocationIsStrip (
|
|||
// Look at the file header to determine if relocations have been stripped, and
|
||||
// save this info in the image context for later use.
|
||||
//
|
||||
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
|
||||
if ((Hdr.Te->DataDirectory[0].Size == 0) && (Hdr.Te->DataDirectory[0].VirtualAddress == 0)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
|
||||
if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
|
||||
if ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
|
|
|
@ -102,7 +102,6 @@
|
|||
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressPeiCodePageNumber ## SOMETIMES_CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressBootTimeCodePageNumber ## SOMETIMES_CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber ## SOMETIMES_CONSUMES
|
||||
|
|
|
@ -328,24 +328,6 @@ SmmLoadImage (
|
|||
&Size,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// Try reading TE section secondly
|
||||
//
|
||||
Buffer = NULL;
|
||||
Size = 0;
|
||||
Status = Fv->ReadSection (
|
||||
Fv,
|
||||
NameGuid,
|
||||
EFI_SECTION_TE,
|
||||
0,
|
||||
&Buffer,
|
||||
&Size,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
if (Buffer != NULL) {
|
||||
gBS->FreePool (Buffer);
|
||||
|
|
|
@ -772,14 +772,6 @@
|
|||
# @Prompt Enable ConOut UGA support.
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE|BOOLEAN|0x00010043
|
||||
|
||||
## Indicates PeiCore will first search TE section from the PEIM to load the image, or PE32 section, when PeiCore dispatches a PEI module.
|
||||
# This PCD is used to tune PEI phase performance to reduce the search image time.
|
||||
# It can be set according to the generated image section type.<BR><BR>
|
||||
# TRUE - PeiCore will first search TE section from PEIM to load the image, if TE section is not found, then PeiCore will search PE section.<BR>
|
||||
# FALSE - PeiCore will first search PE section from PEIM to load the image.<BR>
|
||||
# @Prompt PeiCore search TE section first.
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst|TRUE|BOOLEAN|0x00010044
|
||||
|
||||
## Indicates if to turn off the support of legacy usb. So legacy usb device driver can not make use of SMI
|
||||
# interrupt to access usb device in the case of absence of usb stack.
|
||||
# DUET platform requires the token to be TRUE.<BR><BR>
|
||||
|
|
|
@ -715,12 +715,6 @@
|
|||
"TRUE - Installs UGA Draw Protocol on virtual handle created by ConsplitterDxe.<BR>\n"
|
||||
"FALSE - Does not install UGA Draw Protocol on virtual handle created by ConsplitterDxe.<BR>"
|
||||
|
||||
#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPeiCoreImageLoaderSearchTeSectionFirst_PROMPT #language en-US "PeiCore search TE section first"
|
||||
|
||||
#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPeiCoreImageLoaderSearchTeSectionFirst_HELP #language en-US "Indicates PeiCore will first search TE section from the PEIM to load the image, or PE32 section, when PeiCore dispatches a PEI module. This PCD is used to tune PEI phase performance to reduce the search image time. It can be set according to the generated image section type.<BR><BR>\n"
|
||||
"TRUE - PeiCore will first search TE section from PEIM to load the image, if TE section is not found, then PeiCore will search PE section.<BR>\n"
|
||||
"FALSE - PeiCore will first search PE section from PEIM to load the image.<BR>"
|
||||
|
||||
#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTurnOffUsbLegacySupport_PROMPT #language en-US "Turn off USB legacy support"
|
||||
|
||||
#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTurnOffUsbLegacySupport_HELP #language en-US "Disable legacy USB? If disabled, legacy USB device driver cannot make use of SMI interrupt to access USB device in the case of absence of a USB stack. TRUE - disable<BR>\n"
|
||||
|
|
|
@ -78,7 +78,7 @@ FvFsFindExecutableSection (
|
|||
UINT32 AuthenticationStatus;
|
||||
EFI_STATUS Status;
|
||||
|
||||
for (SectionType = EFI_SECTION_PE32; SectionType <= EFI_SECTION_TE; SectionType++) {
|
||||
for (SectionType = EFI_SECTION_PE32; SectionType <= EFI_SECTION_PIC; SectionType++) {
|
||||
Status = FvProtocol->ReadSection (
|
||||
FvProtocol,
|
||||
&FvFileInfo->NameGuid,
|
||||
|
|
|
@ -724,38 +724,12 @@ typedef struct {
|
|||
} EFI_IMAGE_RESOURCE_DATA_ENTRY;
|
||||
|
||||
///
|
||||
/// Header format for TE images, defined in the PI Specification, 1.0.
|
||||
///
|
||||
typedef struct {
|
||||
UINT16 Signature; ///< The signature for TE format = "VZ".
|
||||
UINT16 Machine; ///< From the original file header.
|
||||
UINT8 NumberOfSections; ///< From the original file header.
|
||||
UINT8 Subsystem; ///< From original optional header.
|
||||
UINT16 StrippedSize; ///< Number of bytes we removed from the header.
|
||||
UINT32 AddressOfEntryPoint; ///< Offset to entry point -- from original optional header.
|
||||
UINT32 BaseOfCode; ///< From original image -- required for ITP debug.
|
||||
UINT64 ImageBase; ///< From original file header.
|
||||
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; ///< Only base relocation and debug directory.
|
||||
} EFI_TE_IMAGE_HEADER;
|
||||
|
||||
|
||||
#define EFI_TE_IMAGE_HEADER_SIGNATURE SIGNATURE_16('V', 'Z')
|
||||
|
||||
//
|
||||
// Data directory indexes in our TE image header
|
||||
//
|
||||
#define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
|
||||
#define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
|
||||
|
||||
|
||||
///
|
||||
/// Union of PE32, PE32+, and TE headers.
|
||||
/// Union of PE32 and PE32+ headers.
|
||||
///
|
||||
typedef union {
|
||||
EFI_IMAGE_NT_HEADERS_COMMON_HDR PeCommon;
|
||||
EFI_IMAGE_NT_HEADERS32 Pe32;
|
||||
EFI_IMAGE_NT_HEADERS64 Pe32Plus;
|
||||
EFI_TE_IMAGE_HEADER Te;
|
||||
} EFI_IMAGE_OPTIONAL_HEADER_UNION;
|
||||
|
||||
#endif // PE_COFF_IMAGE2_H_
|
||||
|
|
|
@ -25,8 +25,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections
|
||||
are retrieved from an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If Buffer is NULL, then ASSERT().
|
||||
|
@ -73,8 +71,6 @@ GetSectionFromAnyFvByFileType (
|
|||
See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections
|
||||
are retrieved from an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If NameGuid is NULL, then ASSERT().
|
||||
|
@ -126,10 +122,6 @@ GetSectionFromAnyFv (
|
|||
See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections are retrieved from
|
||||
an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If the currently executing module was not loaded from a firmware volume, then EFI_NOT_FOUND is returned.
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
If NameGuid is NULL, then ASSERT().
|
||||
If Buffer is NULL, then ASSERT().
|
||||
|
@ -179,9 +171,6 @@ GetSectionFromFv (
|
|||
to use FreePool() to free the allocated buffer. See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for
|
||||
details on how sections are retrieved from an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If the currently executing module was not loaded from an FFS file, then EFI_NOT_FOUND is returned.
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If Buffer is NULL, then ASSERT().
|
||||
|
@ -263,8 +252,6 @@ GetFileBufferByFilePath (
|
|||
The order that the firmware volumes is searched is not deterministic. For each FFS file found a search
|
||||
is made for FFS sections of type SectionType.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If NameGuid is NULL, then ASSERT().
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
/// Image type enumeration for Image format identification from the context.
|
||||
///
|
||||
typedef enum {
|
||||
PeCoffLoaderTypeTe,
|
||||
PeCoffLoaderTypePe32,
|
||||
PeCoffLoaderTypePe32Plus,
|
||||
PeCoffLoaderTypeMax
|
||||
|
@ -128,11 +127,6 @@ typedef struct {
|
|||
///
|
||||
UINT16 Machine;
|
||||
///
|
||||
/// The size, in Bytes, stripped from the beginning of the Image raw file
|
||||
/// during TE file generation. Always 0 for PE Images.
|
||||
///
|
||||
UINT16 TeStrippedOffset;
|
||||
///
|
||||
/// The RVA of the Relocation Directory.
|
||||
///
|
||||
UINT32 RelocDirRva;
|
||||
|
@ -182,7 +176,7 @@ BOOLEAN
|
|||
FileBuffer must remain valid for the entire lifetime of Context.
|
||||
|
||||
@param[out] Context The context describing the Image.
|
||||
@param[in] FileBuffer The file data to parse as TE or PE Image.
|
||||
@param[in] FileBuffer The file data to parse as PE Image.
|
||||
@param[in] FileSize The size, in Bytes, of FileBuffer.
|
||||
|
||||
@retval RETURN_SUCCESS The Image context has been initialised successfully.
|
||||
|
|
|
@ -212,7 +212,6 @@ typedef UINT8 EFI_SECTION_TYPE;
|
|||
///
|
||||
#define EFI_SECTION_PE32 0x10
|
||||
#define EFI_SECTION_PIC 0x11
|
||||
#define EFI_SECTION_TE 0x12
|
||||
#define EFI_SECTION_DXE_DEPEX 0x13
|
||||
#define EFI_SECTION_VERSION 0x14
|
||||
#define EFI_SECTION_USER_INTERFACE 0x15
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderAlignmentPolicy
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderWXorX
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderDebugSupport
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderProhibitTe
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderAllowMisalignedOffset
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugRaisePropertyMask
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderRemoveXForWX
|
||||
|
|
|
@ -7,7 +7,6 @@ An Image Section Table is considered well-formed if and only if:
|
|||
1. The Image Section Table is sorted by Image section RVA in ascending order.
|
||||
2. All Image sections are disjoint in the Image memory space.
|
||||
3. For PE/COFF Images, all Image sections are in bounds of the Image memory space defined by the Image headers.
|
||||
* For TE Images, the Image memory space is implicitly defined by the Image Section Table.
|
||||
4. All Image sections are in bounds of the raw file.
|
||||
|
||||
Additionally, based on PCD policy values, the following constraints may be added:
|
||||
|
|
|
@ -34,7 +34,6 @@ PeCoffGetPdbPath (
|
|||
BOOLEAN Overflow;
|
||||
|
||||
CONST EFI_IMAGE_DATA_DIRECTORY *DebugDir;
|
||||
CONST EFI_TE_IMAGE_HEADER *TeHdr;
|
||||
CONST EFI_IMAGE_NT_HEADERS32 *Pe32Hdr;
|
||||
CONST EFI_IMAGE_NT_HEADERS64 *Pe32PlusHdr;
|
||||
|
||||
|
@ -63,19 +62,6 @@ PeCoffGetPdbPath (
|
|||
// Retrieve the Debug Directory of the Image.
|
||||
//
|
||||
switch (Context->ImageType) {
|
||||
case PeCoffLoaderTypeTe:
|
||||
if (PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
ASSERT (FALSE);
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
TeHdr = (CONST EFI_TE_IMAGE_HEADER *) (CONST VOID *) (
|
||||
(CONST CHAR8 *) Context->FileBuffer
|
||||
);
|
||||
|
||||
DebugDir = &TeHdr->DataDirectory[1];
|
||||
break;
|
||||
|
||||
case PeCoffLoaderTypePe32:
|
||||
Pe32Hdr = (CONST EFI_IMAGE_NT_HEADERS32 *) (CONST VOID *) (
|
||||
(CONST CHAR8 *) Context->FileBuffer + Context->ExeHdrOffset
|
||||
|
@ -170,20 +156,6 @@ PeCoffGetPdbPath (
|
|||
}
|
||||
|
||||
DebugEntryFileOffset = CodeViewEntry->FileOffset;
|
||||
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
Overflow = BaseOverflowSubU32 (
|
||||
DebugEntryFileOffset,
|
||||
Context->TeStrippedOffset,
|
||||
&DebugEntryFileOffset
|
||||
);
|
||||
if (Overflow) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
} else {
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
}
|
||||
//
|
||||
// Verify the CodeView entry is in bounds of the raw file, and the
|
||||
// CodeView entry raw file offset is sufficiently aligned.
|
||||
|
|
|
@ -95,7 +95,6 @@ InternalHashSections (
|
|||
//
|
||||
// 13. Repeat steps 11 and 12 for all of the sections in the sorted table.
|
||||
//
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
for (SectionIndex = 0; SectionIndex < Context->NumberOfSections; ++SectionIndex) {
|
||||
//
|
||||
// Verify the Image section does not overlap with the previous one if the
|
||||
|
@ -196,17 +195,6 @@ PeCoffHashImageAuthenticode (
|
|||
// Additionally, retrieve important offsets for later steps.
|
||||
//
|
||||
switch (Context->ImageType) {
|
||||
case PeCoffLoaderTypeTe:
|
||||
if (PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
//
|
||||
// Authenticode does not define a hashing algorithm for TE Images.
|
||||
//
|
||||
DEBUG_RAISE ();
|
||||
return FALSE;
|
||||
|
||||
case PeCoffLoaderTypePe32:
|
||||
Pe32 = (CONST EFI_IMAGE_NT_HEADERS32 *) (CONST VOID *) (
|
||||
(CONST CHAR8 *) Context->FileBuffer + Context->ExeHdrOffset
|
||||
|
|
|
@ -50,16 +50,6 @@ PeCoffGetHiiDataRva (
|
|||
// Retrieve the Image's Resource Directory Table.
|
||||
//
|
||||
switch (Context->ImageType) {
|
||||
case PeCoffLoaderTypeTe:
|
||||
if (PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
ASSERT (FALSE);
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// TE Images do not contain a Resource Directory Table.
|
||||
//
|
||||
return RETURN_NOT_FOUND;
|
||||
|
||||
case PeCoffLoaderTypePe32:
|
||||
Pe32Hdr = (CONST EFI_IMAGE_NT_HEADERS32 *) (CONST VOID *) (
|
||||
(CONST CHAR8 *) Context->FileBuffer + Context->ExeHdrOffset
|
||||
|
|
|
@ -75,23 +75,9 @@ PeCoffGetSizeOfImageInplace (
|
|||
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
||||
)
|
||||
{
|
||||
UINT32 SizeOfImage;
|
||||
|
||||
ASSERT (Context != NULL);
|
||||
|
||||
SizeOfImage = Context->SizeOfImage;
|
||||
//
|
||||
// SizeOfImage is defined with the full Image header size pre-stripping. As
|
||||
// XIP TE Images always have a stripped Image header, subtract the difference.
|
||||
//
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
ASSERT (Context->TeStrippedOffset < SizeOfImage);
|
||||
SizeOfImage -= Context->TeStrippedOffset;
|
||||
} else {
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
}
|
||||
|
||||
return SizeOfImage;
|
||||
return Context->SizeOfImage;
|
||||
}
|
||||
|
||||
UINT64
|
||||
|
|
|
@ -58,12 +58,10 @@ InternalVerifySections (
|
|||
BOOLEAN Overflow;
|
||||
UINT32 NextSectRva;
|
||||
UINT32 SectRawEnd;
|
||||
UINT32 EffectiveSectRawEnd;
|
||||
UINT16 SectionIndex;
|
||||
CONST EFI_IMAGE_SECTION_HEADER *Sections;
|
||||
|
||||
ASSERT (Context != NULL);
|
||||
ASSERT (Context->TeStrippedOffset <= Context->SizeOfHeaders);
|
||||
ASSERT (IS_POW2 (Context->SectionAlignment));
|
||||
ASSERT (StartAddress != NULL);
|
||||
//
|
||||
|
@ -83,19 +81,6 @@ InternalVerifySections (
|
|||
//
|
||||
if (Sections[0].VirtualAddress == 0) {
|
||||
// FIXME: Add PCD to disallow.
|
||||
//
|
||||
// TE Images cannot support loading the Image Headers as part of the first
|
||||
// Image section due to its StrippedSize sematics.
|
||||
//
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
if (Context->ImageType == PeCoffLoaderTypeTe) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
} else {
|
||||
ASSERT (Context->ImageType != PeCoffLoaderTypeTe);
|
||||
}
|
||||
|
||||
NextSectRva = 0;
|
||||
} else {
|
||||
//
|
||||
|
@ -174,15 +159,6 @@ InternalVerifySections (
|
|||
// Verify the Image sections with data are in bounds of the file buffer.
|
||||
//
|
||||
if (Sections[SectionIndex].SizeOfRawData > 0) {
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
if (Context->TeStrippedOffset > Sections[SectionIndex].PointerToRawData) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
} else {
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
}
|
||||
|
||||
Overflow = BaseOverflowAddU32 (
|
||||
Sections[SectionIndex].PointerToRawData,
|
||||
Sections[SectionIndex].SizeOfRawData,
|
||||
|
@ -193,14 +169,7 @@ InternalVerifySections (
|
|||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
EffectiveSectRawEnd = SectRawEnd - Context->TeStrippedOffset;
|
||||
} else {
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
EffectiveSectRawEnd = SectRawEnd;
|
||||
}
|
||||
|
||||
if (EffectiveSectRawEnd > FileSize) {
|
||||
if (SectRawEnd > FileSize) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
@ -353,131 +322,6 @@ InternalValidateRelocInfo (
|
|||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Verify the TE Image and initialise Context.
|
||||
|
||||
Used offsets and ranges must be aligned and in the bounds of the raw file.
|
||||
Image section Headers and basic Relocation information must be well-formed.
|
||||
|
||||
@param[in,out] Context The context describing the Image. Must have been
|
||||
initialised by PeCoffInitializeContext().
|
||||
@param[in] FileSize The size, in Bytes, of Context->FileBuffer.
|
||||
|
||||
@retval RETURN_SUCCESS The TE Image is well-formed.
|
||||
@retval other The TE Image is malformed.
|
||||
**/
|
||||
STATIC
|
||||
RETURN_STATUS
|
||||
InternalInitializeTe (
|
||||
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context,
|
||||
IN UINT32 FileSize
|
||||
)
|
||||
{
|
||||
RETURN_STATUS Status;
|
||||
BOOLEAN Overflow;
|
||||
CONST EFI_TE_IMAGE_HEADER *TeHdr;
|
||||
UINT32 StartAddress;
|
||||
|
||||
ASSERT (Context != NULL);
|
||||
ASSERT (Context->ExeHdrOffset == 0);
|
||||
ASSERT (sizeof (EFI_TE_IMAGE_HEADER) <= FileSize);
|
||||
|
||||
if (PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
ASSERT (FALSE);
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
TeHdr = (CONST EFI_TE_IMAGE_HEADER *) (CONST VOID *) (
|
||||
(CONST CHAR8 *) Context->FileBuffer
|
||||
);
|
||||
|
||||
Context->ImageType = PeCoffLoaderTypeTe;
|
||||
//
|
||||
// Calculate the size, in Bytes, stripped from the Image Headers.
|
||||
//
|
||||
Overflow = BaseOverflowSubU16 (
|
||||
TeHdr->StrippedSize,
|
||||
sizeof (*TeHdr),
|
||||
&Context->TeStrippedOffset
|
||||
);
|
||||
if (Overflow) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
||||
STATIC_ASSERT (
|
||||
MAX_UINT8 * sizeof (EFI_IMAGE_SECTION_HEADER) <= MAX_UINT32 - MAX_UINT16,
|
||||
"The following arithmetic may overflow."
|
||||
);
|
||||
//
|
||||
// Calculate SizeOfHeaders in a way that is equivalent to what the size would
|
||||
// be if this was the original (unstripped) PE32 binary. As the TE image
|
||||
// creation doesn't fix fields up, values work the same way as for PE32.
|
||||
// When referencing raw data however, the TE stripped size must be subracted.
|
||||
//
|
||||
Context->SizeOfHeaders = (UINT32) TeHdr->StrippedSize + (UINT32) TeHdr->NumberOfSections * sizeof (EFI_IMAGE_SECTION_HEADER);
|
||||
//
|
||||
// Verify that the Image Headers are in bounds of the file buffer.
|
||||
//
|
||||
if (Context->SizeOfHeaders - Context->TeStrippedOffset > FileSize) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
||||
STATIC_ASSERT (
|
||||
IS_ALIGNED (sizeof (*TeHdr), ALIGNOF (EFI_IMAGE_SECTION_HEADER)),
|
||||
"The Image section alignment requirements are violated."
|
||||
);
|
||||
//
|
||||
// TE Image sections start right after the Image Headers.
|
||||
//
|
||||
Context->SectionsOffset = sizeof (EFI_TE_IMAGE_HEADER);
|
||||
//
|
||||
// TE Images do not store their section alignment. Assume the UEFI Page size
|
||||
// by default, as it is the minimum to guarantee memory permission support.
|
||||
//
|
||||
Context->SectionAlignment = EFI_PAGE_SIZE;
|
||||
Context->NumberOfSections = TeHdr->NumberOfSections;
|
||||
//
|
||||
// Validate the sections.
|
||||
// TE images do not have a field to explicitly describe the image size.
|
||||
// Set it to the top of the Image's memory space.
|
||||
//
|
||||
Status = InternalVerifySections (
|
||||
Context,
|
||||
FileSize,
|
||||
&StartAddress
|
||||
);
|
||||
if (Status != RETURN_SUCCESS) {
|
||||
DEBUG_RAISE ();
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Verify the Image entry point is in bounds of the Image buffer.
|
||||
//
|
||||
if (TeHdr->AddressOfEntryPoint >= Context->SizeOfImage) {
|
||||
DEBUG_RAISE ();
|
||||
return RETURN_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
||||
Context->Machine = TeHdr->Machine;
|
||||
Context->Subsystem = TeHdr->Subsystem;
|
||||
Context->ImageBase = TeHdr->ImageBase;
|
||||
Context->AddressOfEntryPoint = TeHdr->AddressOfEntryPoint;
|
||||
Context->RelocDirRva = TeHdr->DataDirectory[0].VirtualAddress;
|
||||
Context->RelocDirSize = TeHdr->DataDirectory[0].Size;
|
||||
//
|
||||
// TE Images do not explicitly store whether their Relocations have been
|
||||
// stripped. Relocations have been stripped if and only if both the RVA and
|
||||
// size of the Relocation Directory are zero.
|
||||
//
|
||||
Context->RelocsStripped = TeHdr->DataDirectory[0].VirtualAddress == 0 && TeHdr->DataDirectory[0].Size == 0;
|
||||
//
|
||||
// Verify basic sanity of the Relocation Directory.
|
||||
//
|
||||
return InternalValidateRelocInfo (Context, StartAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
Verify the PE32 or PE32+ Image and initialise Context.
|
||||
|
||||
|
@ -771,8 +615,6 @@ InternalInitializePe (
|
|||
ASSERT (Context->SecDirOffset == 0);
|
||||
ASSERT (Context->SecDirSize == 0);
|
||||
}
|
||||
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
//
|
||||
// Verify the Image sections are Well-formed.
|
||||
//
|
||||
|
@ -848,24 +690,6 @@ PeCoffInitializeContext (
|
|||
&& !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) {
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
} else if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
//
|
||||
// Assume the Image starts with the Executable Header, determine whether it
|
||||
// is a TE Image.
|
||||
//
|
||||
if (sizeof (EFI_TE_IMAGE_HEADER) <= FileSize
|
||||
&& *(CONST UINT16 *) (CONST VOID *) FileBuffer == EFI_TE_IMAGE_HEADER_SIGNATURE) {
|
||||
//
|
||||
// Verify the TE Image Header is well-formed.
|
||||
//
|
||||
Status = InternalInitializeTe (Context, FileSize);
|
||||
if (Status != RETURN_SUCCESS) {
|
||||
DEBUG_RAISE ();
|
||||
return Status;
|
||||
}
|
||||
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Verify the file buffer can hold a PE Common Header.
|
||||
|
|
|
@ -75,12 +75,7 @@ InternalLoadSections (
|
|||
//
|
||||
// Load the current Image section into the memory space.
|
||||
//
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
EffectivePointerToRawData = Sections[SectionIndex].PointerToRawData - Context->TeStrippedOffset;
|
||||
} else {
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
EffectivePointerToRawData = Sections[SectionIndex].PointerToRawData;
|
||||
}
|
||||
EffectivePointerToRawData = Sections[SectionIndex].PointerToRawData;
|
||||
|
||||
CopyMem (
|
||||
(CHAR8 *) Context->ImageBuffer + Sections[SectionIndex].VirtualAddress,
|
||||
|
@ -122,7 +117,7 @@ PeCoffLoadImage (
|
|||
(CONST CHAR8 *) Context->FileBuffer + Context->SectionsOffset
|
||||
);
|
||||
if (PcdGetBool (PcdImageLoaderLoadHeader) && Sections[0].VirtualAddress != 0) {
|
||||
LoadedHeaderSize = Context->SizeOfHeaders - Context->TeStrippedOffset;
|
||||
LoadedHeaderSize = Context->SizeOfHeaders;
|
||||
CopyMem (Context->ImageBuffer, Context->FileBuffer, LoadedHeaderSize);
|
||||
} else {
|
||||
LoadedHeaderSize = 0;
|
||||
|
@ -144,7 +139,6 @@ PeCoffLoadImageInplaceNoBase (
|
|||
CONST EFI_IMAGE_SECTION_HEADER *Sections;
|
||||
UINT32 AlignedSize;
|
||||
UINT16 SectionIndex;
|
||||
CHAR8 *ImageBuffer;
|
||||
|
||||
ASSERT (Context != NULL);
|
||||
|
||||
|
@ -164,22 +158,7 @@ PeCoffLoadImageInplaceNoBase (
|
|||
}
|
||||
}
|
||||
|
||||
ImageBuffer = (CHAR8 *) Context->FileBuffer;
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
// FIXME: Abstract all accesses to ImageBuffer for safety?
|
||||
//
|
||||
// TE XIP Images are padded to be aligned such that their Image sections
|
||||
// are correctly aligned. ImageBuffer is used exclusively to accesses RVAs,
|
||||
// which for TE XIP Images are always off by Context->TeStrippedOffset.
|
||||
// There is no other way but to treat the data in front of the TE Image
|
||||
// Header as a part of the TE Image Header.
|
||||
//
|
||||
ImageBuffer -= Context->TeStrippedOffset;
|
||||
} else {
|
||||
ASSERT (Context->ImageType != PeCoffLoaderTypeTe);
|
||||
}
|
||||
|
||||
Context->ImageBuffer = ImageBuffer;
|
||||
Context->ImageBuffer = (CHAR8 *) Context->FileBuffer;
|
||||
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
@ -194,12 +173,6 @@ PeCoffImageIsInplace (
|
|||
ASSERT (Context != NULL);
|
||||
|
||||
ImageBase = PeCoffGetImageBase (Context);
|
||||
|
||||
if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
|
||||
ImageBase += Context->TeStrippedOffset;
|
||||
} else {
|
||||
ASSERT (Context->TeStrippedOffset == 0);
|
||||
}
|
||||
//
|
||||
// Verify the Image is located at its preferred load address.
|
||||
//
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
## @file
|
||||
# UEFI Image Loader library implementation for PE/COFF and TE Images.
|
||||
# UEFI Image Loader library implementation for PE/COFF Images.
|
||||
#
|
||||
# Copyright (c) 2021, Marvin Häuser. All rights reserved.<BR>
|
||||
#
|
||||
|
@ -37,6 +37,5 @@
|
|||
[FixedPcd]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderAlignmentPolicy
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderLoadHeader
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderProhibitTe
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugRaisePropertyMask
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderRemoveXForWX
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/** @file
|
||||
UEFI Image Loader library implementation for PE/COFF and TE Images.
|
||||
UEFI Image Loader library implementation for PE/COFF Images.
|
||||
|
||||
Copyright (c) 2021, Marvin Häuser. All rights reserved.<BR>
|
||||
|
||||
|
@ -318,16 +318,14 @@ InternalDebugLocateImage (
|
|||
//
|
||||
// Search for the Image Header in 4 Byte steps. All dynamically loaded
|
||||
// Images start at a page boundary to allow for Image section protection,
|
||||
// but XIP Images may not. As all Image Headers are at least 4 Byte aligned
|
||||
// due to natural alignment, even XIP TE Image Headers should start at a
|
||||
// 4 Byte boundary.
|
||||
// but XIP Images may not.
|
||||
//
|
||||
// Do not attempt to access memory of the first page as it may be protected as
|
||||
// part of NULL dereference detection.
|
||||
//
|
||||
for (; EFI_PAGE_SIZE <= (UINTN) Buffer; Buffer -= 4) {
|
||||
//
|
||||
// Try to parse the current memory as PE/COFF or TE Image. Pass MAX_UINT32
|
||||
// Try to parse the current memory as PE/COFF Image. Pass MAX_UINT32
|
||||
// as the file size as there isn't any more information available. Only the
|
||||
// Image Header memory will be accessed as part of initialisation.
|
||||
//
|
||||
|
@ -348,11 +346,7 @@ InternalDebugLocateImage (
|
|||
// is a part of, if existent. Allow one level of recursion to find a lower
|
||||
// Image Base including the DOS Image Header.
|
||||
//
|
||||
if ((PcdGetBool (PcdImageLoaderProhibitTe)
|
||||
|| Context->ImageType != PeCoffLoaderTypeTe)
|
||||
&& Context->ExeHdrOffset == 0) {
|
||||
ASSERT (Context->ImageType != PeCoffLoaderTypeTe);
|
||||
|
||||
if (Context->ExeHdrOffset == 0) {
|
||||
DosStatus = InternalDebugLocateImage (
|
||||
&DosContext,
|
||||
Buffer - 4,
|
||||
|
@ -368,7 +362,6 @@ InternalDebugLocateImage (
|
|||
//
|
||||
// We know that (UINTN) Buffer <= Address from the initialisation.
|
||||
//
|
||||
// FIXME: Set to non-stripped base for XIP TE Images.
|
||||
if (Address < (UINTN) Buffer + PeCoffGetSizeOfImage (Context)) {
|
||||
Context->ImageBuffer = Buffer;
|
||||
//
|
||||
|
@ -381,7 +374,7 @@ InternalDebugLocateImage (
|
|||
return RETURN_SUCCESS;
|
||||
}
|
||||
//
|
||||
// Continue for the unlikely case that a PE/COFF or TE Image embeds another
|
||||
// Continue for the unlikely case that a PE/COFF Image embeds another
|
||||
// one within its data, the outer Image may still follow.
|
||||
//
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/** @file
|
||||
UEFI Image Loader library implementation for PE/COFF and TE Images.
|
||||
UEFI Image Loader library implementation for PE/COFF Images.
|
||||
|
||||
Copyright (c) 2021, Marvin Häuser. All rights reserved.<BR>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/** @file
|
||||
UEFI Image Loader library implementation for PE/COFF and TE Images.
|
||||
UEFI Image Loader library implementation for PE/COFF Images.
|
||||
|
||||
Copyright (c) 2021, Marvin Häuser. All rights reserved.<BR>
|
||||
|
||||
|
|
|
@ -76,10 +76,6 @@ InternalImageHandleToFvHandle (
|
|||
The details of this search order is defined in description of EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection ()
|
||||
found in PI Specification.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, EFI_SECTION_TE is used as section type to start the search. If EFI_SECTION_TE section
|
||||
is not found, EFI_SECTION_PE32 will be used to try the search again. If no EFI_SECTION_PE32 section is found, EFI_NOT_FOUND
|
||||
is returned.
|
||||
|
||||
The data and size is returned by Buffer and Size. The caller is responsible to free the Buffer allocated
|
||||
by this function. This function can be only called at TPL_NOTIFY and below.
|
||||
|
||||
|
@ -157,23 +153,6 @@ InternalGetSectionFromFv (
|
|||
&AuthenticationStatus
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status) && (SectionType == EFI_SECTION_TE)) {
|
||||
//
|
||||
// Try reading PE32 section, if the required section is TE type
|
||||
//
|
||||
*Buffer = NULL;
|
||||
*Size = 0;
|
||||
Status = Fv->ReadSection (
|
||||
Fv,
|
||||
NameGuid,
|
||||
EFI_SECTION_PE32,
|
||||
SectionInstance,
|
||||
Buffer,
|
||||
Size,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -191,8 +170,6 @@ InternalGetSectionFromFv (
|
|||
See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections
|
||||
are retrieved from an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If Buffer is NULL, then ASSERT().
|
||||
|
@ -338,8 +315,6 @@ Done:
|
|||
See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections
|
||||
are retrieved from an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If NameGuid is NULL, then ASSERT().
|
||||
|
@ -461,10 +436,6 @@ Done:
|
|||
See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for details on how sections are retrieved from
|
||||
an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If the currently executing module was not loaded from a firmware volume, then EFI_NOT_FOUND is returned.
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
If NameGuid is NULL, then ASSERT().
|
||||
If Buffer is NULL, then ASSERT().
|
||||
|
@ -524,9 +495,6 @@ GetSectionFromFv (
|
|||
to use FreePool() to free the allocated buffer. See EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadSection() for
|
||||
details on how sections are retrieved from an FFS file based on SectionType and SectionInstance.
|
||||
|
||||
If the currently executing module was not loaded from an FFS file, then EFI_NOT_FOUND is returned.
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If Buffer is NULL, then ASSERT().
|
||||
|
@ -951,8 +919,6 @@ Finish:
|
|||
The order that the firmware volumes is searched is not deterministic. For each FFS file found a search
|
||||
is made for FFS sections of type SectionType.
|
||||
|
||||
If SectionType is EFI_SECTION_TE, and the search with an FFS file fails,
|
||||
the search will be retried with a section type of EFI_SECTION_PE32.
|
||||
This function must be called with a TPL <= TPL_NOTIFY.
|
||||
|
||||
If NameGuid is NULL, then ASSERT().
|
||||
|
|
|
@ -2289,12 +2289,6 @@
|
|||
# @Prompt Image Loader Alignment Policy.
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderAlignmentPolicy|0xFFFFFFFF|UINT32|0x4000101E
|
||||
|
||||
## Indicates whether TE Images are allowed.<BR><BR>
|
||||
# TRUE - TE Images are forbidden.<BR>
|
||||
# FALSE - TE Images are allowed.<BR>
|
||||
# @Prompt Prohibit TE Images Loading.
|
||||
gEfiMdePkgTokenSpaceGuid.PcdImageLoaderProhibitTe|FALSE|BOOLEAN|0x4000101F
|
||||
|
||||
## Indicates whether PE32+ header offset is sufficiently aligned.<BR><BR>
|
||||
# TRUE - Execution Header offset may be not aligned.<BR>
|
||||
# FALSE - Execution Header offset must be sufficiently aligned.<BR>
|
||||
|
|
|
@ -502,16 +502,8 @@ FindPeiCoreImageBaseInFv (
|
|||
&Section
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = FindFfsFileAndSection (
|
||||
Fv,
|
||||
EFI_FV_FILETYPE_PEI_CORE,
|
||||
EFI_SECTION_TE,
|
||||
&Section
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n"));
|
||||
return Status;
|
||||
}
|
||||
DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
*PeiCoreImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(Section + 1);
|
||||
|
@ -681,7 +673,7 @@ FindImageBase (
|
|||
//
|
||||
// Look for executable sections
|
||||
//
|
||||
if ((Section->Type == EFI_SECTION_PE32) || (Section->Type == EFI_SECTION_TE)) {
|
||||
if (Section->Type == EFI_SECTION_PE32) {
|
||||
if (File->Type == EFI_FV_FILETYPE_SECURITY_CORE) {
|
||||
*SecCoreImageBase = (PHYSICAL_ADDRESS)(UINTN)(Section + 1);
|
||||
*SecCoreImageSize = Size - sizeof (*Section);
|
||||
|
|
|
@ -205,7 +205,7 @@ GetExportDirectoryInPeCoffImage (
|
|||
);
|
||||
|
||||
//
|
||||
// Check the PE/COFF Header Signature. Determine if the image is valid and/or a TE image.
|
||||
// Check the PE/COFF Header Signature. Determine if the image is valid image.
|
||||
//
|
||||
if (OptionalHeaderPtrUnion.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
|
||||
DEBUG ((DEBUG_ERROR, "%a %a: The PE signature is not valid for the current image.\n", _DBGMSGID_, __func__));
|
||||
|
@ -330,7 +330,7 @@ GetImageVersionInPeCoffImage (
|
|||
PeCoffLoaderImageContext->PeCoffHeaderOffset
|
||||
);
|
||||
//
|
||||
// Check the PE/COFF Header Signature. Determine if the image is valid and/or a TE image.
|
||||
// Check the PE/COFF Header Signature. Determine if the image is valid image.
|
||||
//
|
||||
if (OptionalHeaderPtrUnion.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
|
||||
DEBUG ((DEBUG_ERROR, "%a %a: The PE signature is not valid for the current image.\n", _DBGMSGID_, __func__));
|
||||
|
|
|
@ -64,15 +64,12 @@ LocateStandaloneMmCoreUefiImage (
|
|||
|
||||
Status = FfsFindSectionData (EFI_SECTION_PE32, FileHeader, UefiImage, UefiImageSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = FfsFindSectionData (EFI_SECTION_TE, FileHeader, UefiImage, UefiImageSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"Unable to locate Standalone MM Section data - %r\n",
|
||||
Status
|
||||
));
|
||||
return Status;
|
||||
}
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"Unable to locate Standalone MM Section data - %r\n",
|
||||
Status
|
||||
));
|
||||
return Status;
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", *UefiImage));
|
||||
|
|
|
@ -109,7 +109,6 @@ secCoreEntryPointWasFound:
|
|||
OneTimeCallRet Flat32SearchForSecEntryPoint
|
||||
|
||||
%define EFI_SECTION_PE32 0x10
|
||||
%define EFI_SECTION_TE 0x12
|
||||
|
||||
;
|
||||
; Input:
|
||||
|
@ -134,9 +133,6 @@ getEntryPointOfFfsFileLoopForSections:
|
|||
cmp byte [eax + 3], EFI_SECTION_PE32
|
||||
je getEntryPointOfFfsFileFoundPe32Section
|
||||
|
||||
cmp byte [eax + 3], EFI_SECTION_TE
|
||||
je getEntryPointOfFfsFileFoundTeSection
|
||||
|
||||
;
|
||||
; The section type was not PE32 or TE, so move to next section
|
||||
;
|
||||
|
@ -170,22 +166,6 @@ getEntryPointOfFfsFileFoundPe32Section:
|
|||
add eax, [ebx + 0x4 + 0x14 + 0x10]
|
||||
jmp getEntryPointOfFfsFileReturn
|
||||
|
||||
getEntryPointOfFfsFileFoundTeSection:
|
||||
add eax, 4 ; EAX = Start of TE image
|
||||
mov ebx, eax
|
||||
|
||||
; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)
|
||||
cmp word [ebx], 'VZ'
|
||||
jne getEntryPointOfFfsFileErrorReturn
|
||||
; *EntryPoint = (VOID *)((UINTN)Pe32Data +
|
||||
; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +
|
||||
; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
|
||||
add eax, [ebx + 0x8]
|
||||
add eax, 0x28
|
||||
movzx ebx, word [ebx + 0x6]
|
||||
sub eax, ebx
|
||||
jmp getEntryPointOfFfsFileReturn
|
||||
|
||||
getEntryPointOfFfsFileErrorReturn:
|
||||
mov eax, 0
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ FindImageBase (
|
|||
//
|
||||
// Look for executable sections
|
||||
//
|
||||
if ((Section->Type == EFI_SECTION_PE32) || (Section->Type == EFI_SECTION_TE)) {
|
||||
if (Section->Type == EFI_SECTION_PE32) {
|
||||
if (File->Type == FileType) {
|
||||
if (IS_SECTION2 (Section)) {
|
||||
*CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2));
|
||||
|
|
Loading…
Reference in New Issue