From 1e57a46299244793beb27e74be171d1540606999 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Fri, 25 Jan 2013 11:28:06 +0000 Subject: ARM Packages: Fixed line endings This large code change only modifies the line endings to be CRLF to be compliant with the EDK2 coding convention document. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14088 6f19259b-4bc3-4df7-8a09-765794883524 --- ArmPlatformPkg/Scripts/Ds5/build_report.py | 108 ++--- ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py | 434 +++++++++---------- ArmPlatformPkg/Scripts/Ds5/firmware_volume.py | 602 +++++++++++++------------- ArmPlatformPkg/Scripts/Ds5/system_table.py | 258 +++++------ 4 files changed, 701 insertions(+), 701 deletions(-) (limited to 'ArmPlatformPkg/Scripts') diff --git a/ArmPlatformPkg/Scripts/Ds5/build_report.py b/ArmPlatformPkg/Scripts/Ds5/build_report.py index 3805c0b43b..e59230090f 100644 --- a/ArmPlatformPkg/Scripts/Ds5/build_report.py +++ b/ArmPlatformPkg/Scripts/Ds5/build_report.py @@ -1,54 +1,54 @@ -# -# Copyright (c) 2011-2012, ARM Limited. All rights reserved. -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -import re - -class BuildReport: - PCDs = {} - - def parse_platform_summary(self, file): - pass - - def parse_pcd_report(self, report_file): - pcd_reg = re.compile(" (\*P|\*F|\*M| ) (\w+)(\ +)\: (.*) \((\w+)\) = (.*)\n") - - for line in report_file.xreadlines(): - stripped_line = line.strip() - if re.match("\<=+\>", stripped_line): - return - elif re.match("g.*Guid", stripped_line): - guid = stripped_line - self.PCDs[guid] = {} - else: - m = pcd_reg.match(line) - if m: - self.PCDs[guid][m.group(2)] = (m.group(6).strip(),m.group(5)) - - def parse_firmware_device(self, file): - pass - - def parse_module_summary(self, file): - #print "Module Summary" - pass - - CONST_SECTION_HEADERS = [('Platform Summary', parse_platform_summary), - ('Platform Configuration Database Report',parse_pcd_report), - ('Firmware Device (FD)',parse_firmware_device), - ('Module Summary',parse_module_summary)] - - def __init__(self, filename = 'report.log'): - report_file = open(filename, 'r') - for line in report_file.xreadlines(): - for section_header in BuildReport.CONST_SECTION_HEADERS: - if line.strip() == section_header[0]: - section_header[1](self, report_file) - #print self.PCDs +# +# Copyright (c) 2011-2012, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +import re + +class BuildReport: + PCDs = {} + + def parse_platform_summary(self, file): + pass + + def parse_pcd_report(self, report_file): + pcd_reg = re.compile(" (\*P|\*F|\*M| ) (\w+)(\ +)\: (.*) \((\w+)\) = (.*)\n") + + for line in report_file.xreadlines(): + stripped_line = line.strip() + if re.match("\<=+\>", stripped_line): + return + elif re.match("g.*Guid", stripped_line): + guid = stripped_line + self.PCDs[guid] = {} + else: + m = pcd_reg.match(line) + if m: + self.PCDs[guid][m.group(2)] = (m.group(6).strip(),m.group(5)) + + def parse_firmware_device(self, file): + pass + + def parse_module_summary(self, file): + #print "Module Summary" + pass + + CONST_SECTION_HEADERS = [('Platform Summary', parse_platform_summary), + ('Platform Configuration Database Report',parse_pcd_report), + ('Firmware Device (FD)',parse_firmware_device), + ('Module Summary',parse_module_summary)] + + def __init__(self, filename = 'report.log'): + report_file = open(filename, 'r') + for line in report_file.xreadlines(): + for section_header in BuildReport.CONST_SECTION_HEADERS: + if line.strip() == section_header[0]: + section_header[1](self, report_file) + #print self.PCDs diff --git a/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py b/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py index 71e5a3ccd5..87e82b68d6 100644 --- a/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py +++ b/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py @@ -1,217 +1,217 @@ -# -# Copyright (c) 2011-2012, ARM Limited. All rights reserved. -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -import os - -import firmware_volume -import build_report -import system_table - -# Reload external classes -reload(firmware_volume) -reload(build_report) -reload(system_table) - -def readMem32(executionContext, address): - bytes = executionContext.getMemoryService().read(address, 4, 32) - return struct.unpack('= debug_info[0]) and (pc < debug_info[0] + debug_info[1]): - found = True - if found == False: - info = self.firmware_volumes[fv_base].load_symbols_at(pc) - debug_infos.append(info) - - #self.firmware_volumes[fv_base].load_symbols_at(pc) - elif self.in_sysmem(pc): - debug_infos = [] - - if self.system_table is None: - # Find the System Table - self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize) - - # Find the Debug Info Table - debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID) - self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base) - - stack_frame = self.ec.getTopLevelStackFrame() - info = self.debug_info_table.load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF) - debug_infos.append(info) - while stack_frame.next() is not None: - stack_frame = stack_frame.next() - - # Stack frame attached to 'PC' - pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF - - # Check if the symbols for this stack frame have already been loaded - found = False - for debug_info in debug_infos: - if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]): - found = True - if found == False: - info = self.debug_info_table.load_symbols_at(pc) - debug_infos.append(info) - - #self.debug_info_table.load_symbols_at(pc) - else: - raise Exception('ArmPlatformDebugger', "Not supported region") - - def load_all_symbols(self): - # Load all the XIP symbols attached to the Firmware Volume - for (fv_base, fv_size) in self.platform.fvs: - if self.firmware_volumes.has_key(fv_base) == False: - self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size) - self.firmware_volumes[fv_base].load_all_symbols() - - try: - # Load all symbols of module loaded into System Memory - if self.system_table is None: - # Find the System Table - self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize) - - - # Find the Debug Info Table - debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID) - self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base) - - self.debug_info_table.load_all_symbols() - except: - # Debugger exception could be excepted if DRAM has not been initialized or if we have not started to run from DRAM yet - print "Note: no symbols have been found in System Memory (possible cause: the UEFI permanent memory has been installed yet)" - pass +# +# Copyright (c) 2011-2012, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +import os + +import firmware_volume +import build_report +import system_table + +# Reload external classes +reload(firmware_volume) +reload(build_report) +reload(system_table) + +def readMem32(executionContext, address): + bytes = executionContext.getMemoryService().read(address, 4, 32) + return struct.unpack('= debug_info[0]) and (pc < debug_info[0] + debug_info[1]): + found = True + if found == False: + info = self.firmware_volumes[fv_base].load_symbols_at(pc) + debug_infos.append(info) + + #self.firmware_volumes[fv_base].load_symbols_at(pc) + elif self.in_sysmem(pc): + debug_infos = [] + + if self.system_table is None: + # Find the System Table + self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize) + + # Find the Debug Info Table + debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID) + self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base) + + stack_frame = self.ec.getTopLevelStackFrame() + info = self.debug_info_table.load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF) + debug_infos.append(info) + while stack_frame.next() is not None: + stack_frame = stack_frame.next() + + # Stack frame attached to 'PC' + pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF + + # Check if the symbols for this stack frame have already been loaded + found = False + for debug_info in debug_infos: + if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]): + found = True + if found == False: + info = self.debug_info_table.load_symbols_at(pc) + debug_infos.append(info) + + #self.debug_info_table.load_symbols_at(pc) + else: + raise Exception('ArmPlatformDebugger', "Not supported region") + + def load_all_symbols(self): + # Load all the XIP symbols attached to the Firmware Volume + for (fv_base, fv_size) in self.platform.fvs: + if self.firmware_volumes.has_key(fv_base) == False: + self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size) + self.firmware_volumes[fv_base].load_all_symbols() + + try: + # Load all symbols of module loaded into System Memory + if self.system_table is None: + # Find the System Table + self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize) + + + # Find the Debug Info Table + debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID) + self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base) + + self.debug_info_table.load_all_symbols() + except: + # Debugger exception could be excepted if DRAM has not been initialized or if we have not started to run from DRAM yet + print "Note: no symbols have been found in System Memory (possible cause: the UEFI permanent memory has been installed yet)" + pass diff --git a/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py b/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py index c4e02ece24..a13d1433eb 100644 --- a/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py +++ b/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py @@ -1,301 +1,301 @@ -# -# Copyright (c) 2011-2012, ARM Limited. All rights reserved. -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -from arm_ds.debugger_v1 import DebugException - -import struct -import string - -import edk2_debugger - -class EfiFileSection(object): - EFI_SECTION_PE32 = 0x10 - EFI_SECTION_PIC = 0x11 - EFI_SECTION_TE = 0x12 - - EFI_IMAGE_DEBUG_TYPE_CODEVIEW = 0x2 - - SIZEOF_EFI_FFS_FILE_HEADER = 0x28 - - def __init__(self, ec, base): - self.base = base - self.ec = ec - - def __str__(self): - return "FileSection(type:0x%X, size:0x%x)" % (self.get_type(), self.get_size()) - - def get_base(self): - return self.base - - def get_type(self): - return struct.unpack("B", self.ec.getMemoryService().read(self.base + 0x3, 1, 8))[0] - - def get_size(self): - return (struct.unpack(">= 1 - - return highest_bit - - def get_next_section(self, section=None): - if section == None: - if self.get_type() != FirmwareFile.EFI_FV_FILETYPE_FFS_MIN: - section_base = self.get_base() + 0x18; - else: - return None - else: - section_base = int(section.get_base() + section.get_size()) - - # Align to next 4 byte boundary - if (section_base & 0x3) != 0: - section_base = section_base + 0x4 - (section_base & 0x3) - - if section_base < self.get_base() + self.get_size(): - return EfiFileSection(self.ec, section_base) - else: - return None - -class FirmwareVolume: - CONST_FV_SIGNATURE = ('_','F','V','H') - EFI_FVB2_ERASE_POLARITY = 0x800 - - DebugInfos = [] - - def __init__(self, ec, fv_base, fv_size): - self.ec = ec - self.fv_base = fv_base - self.fv_size = fv_size - - try: - signature = struct.unpack("cccc", self.ec.getMemoryService().read(fv_base + 0x28, 4, 32)) - except DebugException: - raise Exception("FirmwareVolume", "Not possible to access the defined firmware volume at [0x%X,0x%X]. Could be the used build report does not correspond to your current debugging context." % (int(fv_base),int(fv_base+fv_size))) - if signature != FirmwareVolume.CONST_FV_SIGNATURE: - raise Exception("FirmwareVolume", "This is not a valid firmware volume") - - def get_size(self): - return self.ec.getMemoryService().readMemory32(self.fv_base + 0x20) - - def get_attributes(self): - return self.ec.getMemoryService().readMemory32(self.fv_base + 0x2C) - - def get_polarity(self): - attributes = self.get_attributes() - if attributes & FirmwareVolume.EFI_FVB2_ERASE_POLARITY: - return 1 - else: - return 0 - - def get_next_ffs(self, ffs=None): - if ffs == None: - # Get the offset of the first FFS file from the FV header - ffs_base = self.fv_base + self.ec.getMemoryService().readMemory16(self.fv_base + 0x30) - else: - # Goto the next FFS file - ffs_base = int(ffs.get_base() + ffs.get_size()) - - # Align to next 8 byte boundary - if (ffs_base & 0x7) != 0: - ffs_base = ffs_base + 0x8 - (ffs_base & 0x7) - - if ffs_base < self.fv_base + self.get_size(): - return FirmwareFile(self, ffs_base, self.ec) - else: - return None - - def get_debug_info(self): - self.DebugInfos = [] - - ffs = self.get_next_ffs() - while ffs != None: - section = ffs.get_next_section() - while section != None: - type = section.get_type() - if (type == EfiFileSection.EFI_SECTION_TE) or (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) - - def load_symbols_at(self, addr): - if self.DebugInfos == []: - self.get_debug_info() - - 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: - section = EfiSectionPE32(self.ec, debug_info[0] + 0x4) - else: - raise Exception('FirmwareVolume','Section Type not supported') - - edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) - - return debug_info - - def load_all_symbols(self): - if self.DebugInfos == []: - 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: - section = EfiSectionPE32(self.ec, debug_info[0] + 0x4) - else: - continue - - edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) +# +# Copyright (c) 2011-2012, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +from arm_ds.debugger_v1 import DebugException + +import struct +import string + +import edk2_debugger + +class EfiFileSection(object): + EFI_SECTION_PE32 = 0x10 + EFI_SECTION_PIC = 0x11 + EFI_SECTION_TE = 0x12 + + EFI_IMAGE_DEBUG_TYPE_CODEVIEW = 0x2 + + SIZEOF_EFI_FFS_FILE_HEADER = 0x28 + + def __init__(self, ec, base): + self.base = base + self.ec = ec + + def __str__(self): + return "FileSection(type:0x%X, size:0x%x)" % (self.get_type(), self.get_size()) + + def get_base(self): + return self.base + + def get_type(self): + return struct.unpack("B", self.ec.getMemoryService().read(self.base + 0x3, 1, 8))[0] + + def get_size(self): + return (struct.unpack(">= 1 + + return highest_bit + + def get_next_section(self, section=None): + if section == None: + if self.get_type() != FirmwareFile.EFI_FV_FILETYPE_FFS_MIN: + section_base = self.get_base() + 0x18; + else: + return None + else: + section_base = int(section.get_base() + section.get_size()) + + # Align to next 4 byte boundary + if (section_base & 0x3) != 0: + section_base = section_base + 0x4 - (section_base & 0x3) + + if section_base < self.get_base() + self.get_size(): + return EfiFileSection(self.ec, section_base) + else: + return None + +class FirmwareVolume: + CONST_FV_SIGNATURE = ('_','F','V','H') + EFI_FVB2_ERASE_POLARITY = 0x800 + + DebugInfos = [] + + def __init__(self, ec, fv_base, fv_size): + self.ec = ec + self.fv_base = fv_base + self.fv_size = fv_size + + try: + signature = struct.unpack("cccc", self.ec.getMemoryService().read(fv_base + 0x28, 4, 32)) + except DebugException: + raise Exception("FirmwareVolume", "Not possible to access the defined firmware volume at [0x%X,0x%X]. Could be the used build report does not correspond to your current debugging context." % (int(fv_base),int(fv_base+fv_size))) + if signature != FirmwareVolume.CONST_FV_SIGNATURE: + raise Exception("FirmwareVolume", "This is not a valid firmware volume") + + def get_size(self): + return self.ec.getMemoryService().readMemory32(self.fv_base + 0x20) + + def get_attributes(self): + return self.ec.getMemoryService().readMemory32(self.fv_base + 0x2C) + + def get_polarity(self): + attributes = self.get_attributes() + if attributes & FirmwareVolume.EFI_FVB2_ERASE_POLARITY: + return 1 + else: + return 0 + + def get_next_ffs(self, ffs=None): + if ffs == None: + # Get the offset of the first FFS file from the FV header + ffs_base = self.fv_base + self.ec.getMemoryService().readMemory16(self.fv_base + 0x30) + else: + # Goto the next FFS file + ffs_base = int(ffs.get_base() + ffs.get_size()) + + # Align to next 8 byte boundary + if (ffs_base & 0x7) != 0: + ffs_base = ffs_base + 0x8 - (ffs_base & 0x7) + + if ffs_base < self.fv_base + self.get_size(): + return FirmwareFile(self, ffs_base, self.ec) + else: + return None + + def get_debug_info(self): + self.DebugInfos = [] + + ffs = self.get_next_ffs() + while ffs != None: + section = ffs.get_next_section() + while section != None: + type = section.get_type() + if (type == EfiFileSection.EFI_SECTION_TE) or (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) + + def load_symbols_at(self, addr): + if self.DebugInfos == []: + self.get_debug_info() + + 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: + section = EfiSectionPE32(self.ec, debug_info[0] + 0x4) + else: + raise Exception('FirmwareVolume','Section Type not supported') + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) + + return debug_info + + def load_all_symbols(self): + if self.DebugInfos == []: + 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: + section = EfiSectionPE32(self.ec, debug_info[0] + 0x4) + else: + continue + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) diff --git a/ArmPlatformPkg/Scripts/Ds5/system_table.py b/ArmPlatformPkg/Scripts/Ds5/system_table.py index f489e466ad..8dec591e63 100644 --- a/ArmPlatformPkg/Scripts/Ds5/system_table.py +++ b/ArmPlatformPkg/Scripts/Ds5/system_table.py @@ -1,129 +1,129 @@ -# -# Copyright (c) 2011-2012, ARM Limited. All rights reserved. -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -from arm_ds.debugger_v1 import DebugException - -import struct - -import edk2_debugger -import firmware_volume - -class DebugInfoTable: - CONST_DEBUG_INFO_TABLE_GUID = ( 0x49152E77L, 0x47641ADAL, 0xFE7AA2B7L, 0x8B5ED9FEL) - - DebugInfos = [] - - def __init__(self, ec, debug_info_table_header_offset): - self.ec = ec - self.base = debug_info_table_header_offset - - def get_debug_info(self): - count = self.ec.getMemoryService().readMemory32(self.base + 0x4) - debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8) - - self.DebugInfos = [] - - for i in range(0, count): - # Get the address of the structure EFI_DEBUG_IMAGE_INFO - debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4)) - if debug_info: - debug_info_type = self.ec.getMemoryService().readMemory32(debug_info) - # Normal Debug Info Type - if debug_info_type == 1: - # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL - loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4) - - image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20) - image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28) - - self.DebugInfos.append((image_base,image_size)) - - # Return (base, size) - def load_symbols_at(self, addr): - if self.DebugInfos == []: - self.get_debug_info() - - found = False - for debug_info in self.DebugInfos: - if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]): - section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) - - edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) - - found = True - return debug_info - - if found == False: - raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr) - - def load_all_symbols(self): - if self.DebugInfos == []: - self.get_debug_info() - - for debug_info in self.DebugInfos: - section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) - - edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) - - def dump(self): - self.get_debug_info() - for debug_info in self.DebugInfos: - base_pe32 = debug_info[0] - section = firmware_volume.EfiSectionPE32(self.ec, base_pe32) - print section.get_debug_filepath() - -class SystemTable: - CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T') - - def __init__(self, ec, membase, memsize): - self.membase = membase - self.memsize = memsize - self.ec = ec - - found = False - - # Start from the top of the memory - offset = self.membase + self.memsize - # Align to highest 4MB boundary - offset = offset & ~0x3FFFFF - # We should not have a System Table at the top of the System Memory - offset = offset - 0x400000 - - # Start at top and look on 4MB boundaries for system table ptr structure - while offset > self.membase: - try: - signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32)) - except DebugException: - raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize)) - if signature == SystemTable.CONST_ST_SIGNATURE: - found = True - self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8) - break - offset = offset - 0x400000 - - if not found: - raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize)) - - def get_configuration_table(self, conf_table_guid): - # Number of configuration Table entry - conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40) - - # Get location of the Configuration Table entries - conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44) - - for i in range(0, conf_table_entry_count): - offset = conf_table_offset + (i * 0x14) - guid = struct.unpack("= debug_info[0]) and (addr < debug_info[0] + debug_info[1]): + section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) + + found = True + return debug_info + + if found == False: + raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr) + + def load_all_symbols(self): + if self.DebugInfos == []: + self.get_debug_info() + + for debug_info in self.DebugInfos: + section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) + + def dump(self): + self.get_debug_info() + for debug_info in self.DebugInfos: + base_pe32 = debug_info[0] + section = firmware_volume.EfiSectionPE32(self.ec, base_pe32) + print section.get_debug_filepath() + +class SystemTable: + CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T') + + def __init__(self, ec, membase, memsize): + self.membase = membase + self.memsize = memsize + self.ec = ec + + found = False + + # Start from the top of the memory + offset = self.membase + self.memsize + # Align to highest 4MB boundary + offset = offset & ~0x3FFFFF + # We should not have a System Table at the top of the System Memory + offset = offset - 0x400000 + + # Start at top and look on 4MB boundaries for system table ptr structure + while offset > self.membase: + try: + signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32)) + except DebugException: + raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize)) + if signature == SystemTable.CONST_ST_SIGNATURE: + found = True + self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8) + break + offset = offset - 0x400000 + + if not found: + raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize)) + + def get_configuration_table(self, conf_table_guid): + # Number of configuration Table entry + conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40) + + # Get location of the Configuration Table entries + conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44) + + for i in range(0, conf_table_entry_count): + offset = conf_table_offset + (i * 0x14) + guid = struct.unpack("