mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
BaseTools: Scripts: efi_debugging.py: search for EFI_SYSTEM_TABLE_POINTER
Add code to search for gST via EFI_SYSTEM_TABLE_POINTER. Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
This commit is contained in:
parent
55b4688157
commit
d985bd4b97
1 changed files with 34 additions and 2 deletions
|
|
@ -33,6 +33,7 @@ import os
|
|||
import uuid
|
||||
import struct
|
||||
import re
|
||||
import zlib
|
||||
from ctypes import c_char, c_uint8, c_uint16, c_uint32, c_uint64, c_void_p
|
||||
from ctypes import ARRAY, sizeof
|
||||
from ctypes import Structure, LittleEndianStructure
|
||||
|
|
@ -1770,8 +1771,10 @@ class EfiConfigurationTable:
|
|||
def __init__(self, file, gST_addr=None):
|
||||
self._file = file
|
||||
if gST_addr is None:
|
||||
# ToDo add code to search for gST via EFI_SYSTEM_TABLE_POINTER
|
||||
return
|
||||
# search for gST via EFI_SYSTEM_TABLE_POINTER
|
||||
system_table_pointer = self._get_system_table_pointer()
|
||||
if not system_table_pointer is None:
|
||||
gST_addr = system_table_pointer.EfiSystemTableBase
|
||||
|
||||
gST = self._ctype_read(EFI_SYSTEM_TABLE, gST_addr)
|
||||
self.read_efi_config_table(gST.NumberOfTableEntries,
|
||||
|
|
@ -1796,6 +1799,35 @@ class EfiConfigurationTable:
|
|||
data = self._file.read(sizeof(ctype_struct))
|
||||
return ctype_struct.from_buffer(bytearray(data))
|
||||
|
||||
def _get_system_table_pointer(self):
|
||||
start_addr = 0x0
|
||||
end_addr = 0xf0000000
|
||||
alignment = 0x00400000
|
||||
# The translation of "IBI SYST" for the signature of EFI_SYSTEM_TABLE
|
||||
efi_system_table_signature = 0x5453595320494249
|
||||
|
||||
system_table_pointer = None
|
||||
|
||||
current_addr = start_addr
|
||||
while current_addr < end_addr:
|
||||
try:
|
||||
self._file.seek(current_addr)
|
||||
data = self._file.read(sizeof(EFI_SYSTEM_TABLE_POINTER))
|
||||
except:
|
||||
current_addr = current_addr + alignment
|
||||
continue
|
||||
|
||||
system_table_pointer = EFI_SYSTEM_TABLE_POINTER.from_buffer(bytearray(data))
|
||||
if system_table_pointer.Signature == efi_system_table_signature:
|
||||
buf1 = bytearray(system_table_pointer)[:16]
|
||||
crc32_value = zlib.crc32(buf1)
|
||||
crc32_value = zlib.crc32(b'\0' * (sizeof(EFI_SYSTEM_TABLE_POINTER) - len(buf1)), crc32_value)
|
||||
if crc32_value == system_table_pointer.Crc32:
|
||||
break
|
||||
system_table_pointer = None
|
||||
current_addr = current_addr + alignment
|
||||
return system_table_pointer
|
||||
|
||||
@ classmethod
|
||||
def read_efi_config_table(cls, table_cnt, table_ptr, ctype_read):
|
||||
'''Create a dictionary of EFI Configuration table entries'''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue