def DmpVariable(name, guid): DataSize = EfiPy.UINTN(0x00) Status = EfiPy.gRT.GetVariable(name, EfiPy.byref(guid), None, EfiPy.byref(DataSize), None) if Status != EfiPy.EFI_BUFFER_TOO_SMALL: return Attributes = EfiPy.UINT32(0x00) DataBuffer = (EfiPy.CHAR8 * DataSize.value)("\00") Status = EfiPy.gRT.GetVariable(name, EfiPy.byref(guid), EfiPy.byref(Attributes), EfiPy.byref(DataSize), EfiPy.byref(DataBuffer)) if not EfiPy.RETURN_ERROR(Status): StrVarAttr = "" if (Attributes.value & EfiPy.EFI_VARIABLE_NON_VOLATILE) > 0: StrVarAttr = "NV" if (Attributes.value & EfiPy.EFI_VARIABLE_RUNTIME_ACCESS) > 0: if len(StrVarAttr) > 0: StrVarAttr = StrVarAttr + "+" StrVarAttr = StrVarAttr + "RS" if (Attributes.value & EfiPy.EFI_VARIABLE_BOOTSERVICE_ACCESS) > 0: if len(StrVarAttr) > 0: StrVarAttr = StrVarAttr + "+" StrVarAttr = StrVarAttr + "BS" print print "Variable - %s - '%s:%s' - DataSize = 0x%X" % ( StrVarAttr, guid, name, DataSize.value) EfiPyHexDump(0, 0x0000, DataBuffer, True) else: print "Get Variable %s %s error" % (name, guid)
def EfiPyDumpBoot(): DataSize = EfiPy.UINTN(0x00) Status = EfiPy.gRT.GetVariable(EFI_BOOT_ORDER_VARIABLE_NAME, EfiPy.byref(gEfiGlobalVariableGuid), None, EfiPy.byref(DataSize), None) if Status != EfiPy.EFI_BUFFER_TOO_SMALL: return 0 Attributes = EfiPy.UINT32(0x00) DataBuffer = (EfiPy.CHAR8 * DataSize.value)("\00") Status = EfiPy.gRT.GetVariable(EFI_BOOT_ORDER_VARIABLE_NAME, EfiPy.byref(gEfiGlobalVariableGuid), EfiPy.byref(Attributes), EfiPy.byref(DataSize), EfiPy.byref(DataBuffer)) if Status != EfiPy.EFI_SUCCESS: return 0 import struct BootOrder = struct.unpack("H" * (DataSize.value / 2), DataBuffer) BootOrder = [u"Boot" + ("%04X" % s) for s in BootOrder] BootOrder.append(EFI_BOOT_NEXT_VARIABLE_NAME) print str(BootOrder) print "Boot### content" for LoadOptionName in BootOrder: DataSize = EfiPy.UINTN(0x00) Status = EfiPy.gRT.GetVariable(LoadOptionName, EfiPy.byref(gEfiGlobalVariableGuid), None, EfiPy.byref(DataSize), None) if Status != EfiPy.EFI_BUFFER_TOO_SMALL: continue Attributes = EfiPy.UINT32(0x00) DataBuffer = (EfiPy.CHAR8 * DataSize.value)("\00") Status = EfiPy.gRT.GetVariable(LoadOptionName, EfiPy.byref(gEfiGlobalVariableGuid), EfiPy.byref(Attributes), EfiPy.byref(DataSize), EfiPy.byref(DataBuffer)) if RETURN_ERROR(Status): print LoadOptionName + " does not exit!" continue DmpVariable(LoadOptionName, gEfiGlobalVariableGuid) (LoAttributes, LoFlen) = struct.unpack_from('IH', DataBuffer, 0) DescriptionEnd = len(DataBuffer[6:].split('\x00\x00')[0]) + 9 FilePathListEnd = DescriptionEnd + LoFlen - 2 DescriptionVar = DataBuffer[6:DescriptionEnd - 2].decode('utf_16') FilePathListVar = DataBuffer[DescriptionEnd:FilePathListEnd] print "Attributes: 0x%04X, FilePathListLength: 0x%02X " % ( LoAttributes, LoFlen) print "Description: '%s'" % DescriptionVar DevicePath = EfiPy.cast(FilePathListVar, POINTER(EFI_DEVICE_PATH_PROTOCOL)).contents DevicePath.DisplayOnly = True # DevicePath.DisplayOnly = False DevicePath.AllowShortcuts = False print "DevicePath:\n %s" % DevicePath print "OptionalData:" EfiPyHexDump(0, 0x0000, DataBuffer[FilePathListEnd:], True) return 0
def AcpiDump (AcpiName, FullDump = False): import struct for _signature, _address, _length in AcpiBase.AcpiTables: if AcpiName in 'RSD PTR ' and _signature in 'RSD PTR ': print " RSDP:Signature: '%s'" % struct.pack ("Q", AcpiBase.Rsdp.Signature) print " RSDP:Checksum: 0x%02X" % AcpiBase.Rsdp.Checksum print " RSDP:OemId: '%s'" % bytearray (AcpiBase.Rsdp.OemId) print " RSDP:Revision: 0x%02X" % AcpiBase.Rsdp.Revision print " RSDP:RsdtAddress: 0x%08X" % AcpiBase.Rsdp.RsdtAddress print " RSDP:Length: 0x%02X" % AcpiBase.Rsdp.Length print " RSDP:XsdtAddress: 0x%016X" % AcpiBase.Rsdp.XsdtAddress print " RSDP:ExtendedChecksum: 0x%02X" % AcpiBase.Rsdp.ExtendedChecksum if FullDump == True: _cAddress = _address _cLength = _length _Memory = (EfiPy.CHAR8 * (_cLength)).from_address (_cAddress) EfiPyHexDump (2, _cAddress, _Memory, True, AcpiName) return elif AcpiName in 'FACS' and _signature in 'FACS': # TODO print " FACS:Signature: '%s'" % AcpiName print " FACS:Length: 0x%02X" % _length print " FACS spec size: 0x%04X" % EfiPy.sizeof (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE) if FullDump == True: _cAddress = _address _cLength = _length _Memory = (EfiPy.CHAR8 * (_cLength)).from_address (_cAddress) EfiPyHexDump (2, _cAddress, _Memory, True, AcpiName) return elif AcpiName in _signature: _Header = EFI_ACPI_DESCRIPTION_HEADER.from_address (_address) print " %s:Signature: '%s'" % (AcpiName, struct.pack ("I", _Header.Signature)) print " %s:Length: 0x%08X" % (AcpiName, _Header.Length) print " %s:Revision: 0x%02X" % (AcpiName, _Header.Revision) print " %s:Checksum: 0x%02X" % (AcpiName, _Header.Checksum) print " %s:OemId: '%s'" % (AcpiName, bytearray (_Header.OemId)) print " %s:OemTableId: '%s'" % (AcpiName, struct.pack ("Q", _Header.OemTableId)) print " %s:OemRevision: 0x%08X" % (AcpiName, _Header.OemRevision) print " %s:CreatorId: '%s'" % (AcpiName, struct.pack ("I", _Header.CreatorId)) print " %s:CreatorRevision: 0x%08X" % (AcpiName, _Header.CreatorRevision) if FullDump == True: _cAddress = _address _cLength = _length else: _cAddress = _address + EfiPy.sizeof (EFI_ACPI_DESCRIPTION_HEADER) _cLength = _length - EfiPy.sizeof (EFI_ACPI_DESCRIPTION_HEADER) _Memory = (EfiPy.CHAR8 * (_cLength)).from_address (_cAddress) EfiPyHexDump (2, _cAddress, _Memory, True, AcpiName)
import EfiPyLib.Acpi.AcpiMcfg as AcpiMcfg print " MCFG Revision: 0x%02X" % AcpiMcfg.Revision print " MCFG Address: 0x%08X" % AcpiMcfg.Address print " MCFG Size: 0x%08X" % AcpiMcfg.Size print " AcpiMcfg:Signature: %s" % struct.pack ("I", AcpiMcfg.Table.Header.Header.Signature) print " AcpiMcfg:Length: 0x%08X" % AcpiMcfg.Table.Header.Header.Length print " AcpiMcfg:Revision: 0x%02X" % AcpiMcfg.Table.Header.Header.Revision print " AcpiMcfg:Checksum: 0x%02X" % AcpiMcfg.Table.Header.Header.Checksum print " AcpiMcfg:OemId: %s" % bytearray (AcpiMcfg.Table.Header.Header.OemId) print " AcpiMcfg:OemTableId: %s" % struct.pack ("Q", AcpiMcfg.Table.Header.Header.OemTableId) print " AcpiMcfg:OemRevision: 0x%08X" % AcpiMcfg.Table.Header.Header.OemRevision print " AcpiMcfg:CreatorId: %s" % struct.pack ("I", AcpiMcfg.Table.Header.Header.CreatorId) print " AcpiMcfg:CreatorRevision: 0x%08X" % AcpiMcfg.Table.Header.Header.CreatorRevision for dTable in AcpiMcfg.Table.McfgEntry: print " Mcfg: " + "=" * 10 print " Mcfg.BaseAddress: 0x%016X" % dTable.BaseAddress print " Mcfg.PciSegmentGroupNumber: 0x%08X" % dTable.PciSegmentGroupNumber print " Mcfg.StartBusNumber: 0x%08X" % dTable.StartBusNumber print " Mcfg.EndBusNumber: 0x%08X" % dTable.EndBusNumber import EfiPy if AcpiMcfg.Size != EfiPy.sizeof (AcpiMcfg.Table): print "WARNNING: MCFG size and Spec defined size are inconsistent." print " MCFG size: %d, Spec defined size: %d" % (AcpiMcfg.Size, EfiPy.sizeof (AcpiMcfg.Table)) print from EfiPyLib.EfiPyHexDump import EfiPyHexDump Memory = (EfiPy.CHAR8 * AcpiMcfg.Size).from_address (AcpiMcfg.Address) EfiPyHexDump (2, AcpiMcfg.Address, Memory, True, "ACPI: MCFP")
from EfiPy import * from EfiPy.MdePkg.Protocol.LoadedImage import EFI_LOADED_IMAGE_PROTOCOL, gEfiLoadedImageProtocolGuid from EfiPy.MdePkg.IndustryStandard.PeImage import EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION, EFI_IMAGE_OPTIONAL_HEADER_UNION, EFI_IMAGE_DOS_HEADER, EFI_IMAGE_OPTIONAL_HEADER_UNION, EFI_IMAGE_SECTION_HEADER from EfiPyLib.EfiPyHexDump import EfiPyHexDump TmpProtocol = PVOID() Status = gBS.HandleProtocol(gImageHandle, byref(gEfiLoadedImageProtocolGuid), byref(TmpProtocol)) if (EFI_ERROR(Status)): print "Locate gEfiLoadedImageProtocolGuid error %X" % Status exit(-1) LoadedImage = cast(TmpProtocol, POINTER(EFI_LOADED_IMAGE_PROTOCOL))[0] DumpBuff = cast(LoadedImage.ImageBase, POINTER(CHAR8 * 0x400)) EfiPyHexDump(0x00, 0x00, DumpBuff[0]) DosHeader = cast(LoadedImage.ImageBase, POINTER(EFI_IMAGE_DOS_HEADER))[0] print "Image size: 0x%08X" % LoadedImage.ImageSize print "DosHeader at 0x%016X" % addressof(DosHeader) print "DosHeader.e_lfanew: 0x%08X" % DosHeader.e_lfanew class ImageClass(Structure): _fields_ = [ ("PreHeader", UINT8 * DosHeader.e_lfanew), ("PeHeader", EFI_IMAGE_OPTIONAL_HEADER_UNION), ]
AcpiHpet.Table), AcpiHpet.Table.Header.Length) print " Signature: %s" % struct.pack( "I", AcpiHpet.Table.Header.Signature) print " Length: 0x%08X" % AcpiHpet.Table.Header.Length print " Revision: 0x%02X" % AcpiHpet.Table.Header.Revision print " Checksum: 0x%02X" % AcpiHpet.Table.Header.Checksum print " OemId: %s" % bytearray( AcpiHpet.Table.Header.OemId) print " OemTableId: %s" % struct.pack( "Q", AcpiHpet.Table.Header.OemTableId) print " OemRevision: 0x%08X" % AcpiHpet.Table.Header.OemRevision print " CreatorId: %s" % struct.pack( "I", AcpiHpet.Table.Header.CreatorId) print " CreatorRevision: 0x%08X" % AcpiHpet.Table.Header.CreatorRevision print " EventTimerBlockID: 0x%08X" % AcpiHpet.Table.EventTimerBlockID print " BaseAddressLower32Bit.AddressSpaceId: 0x%08X" % AcpiHpet.Table.BaseAddressLower32Bit.AddressSpaceId print " BaseAddressLower32Bit.RegisterBitWidth: 0x%08X" % AcpiHpet.Table.BaseAddressLower32Bit.RegisterBitWidth print " BaseAddressLower32Bit.RegisterBitOffset: 0x%08X" % AcpiHpet.Table.BaseAddressLower32Bit.RegisterBitOffset print " BaseAddressLower32Bit.AccessSize: 0x%08X" % AcpiHpet.Table.BaseAddressLower32Bit.AccessSize print " BaseAddressLower32Bit.Address: 0x%016X" % AcpiHpet.Table.BaseAddressLower32Bit.Address print " HpetNumber: 0x%02X" % AcpiHpet.Table.HpetNumber print " Mode: 0x%04X" % AcpiHpet.Table.Mode print " Attribute: 0x%02X" % AcpiHpet.Table.Attribute print from EfiPyLib.EfiPyHexDump import EfiPyHexDump Memory = (EfiPy.CHAR8 * AcpiHpet.Size).from_address(AcpiHpet.Address) EfiPyHexDump(2, AcpiHpet.Address, Memory, True, "ACPI: HPET")
# # Dump PCI bus 0, device 0, function 0 MMIO # print print "==== Sample 5. Dump MMIO space by ACPI Mcfg" import sys import traceback try: import EfiPy from EfiPyLib.EfiPyHexDump import EfiPyHexDump from EfiPyLib.Acpi.AcpiMcfg import Table as McfgTable for pcid in PciList: print DeviceMmioBase = McfgTable.McfgEntry[0].BaseAddress + PciMmioConfigOffset (pcid[0], pcid[1], pcid[2], 0) Memory = (EfiPy.CHAR8 * 0x100).from_address (DeviceMmioBase) EfiPyHexDump (2, DeviceMmioBase, Memory, True, "PCI%s" % str(pcid)) except Exception as e: exc_type, exc_value, exc_traceback_obj = sys.exc_info() traceback.print_tb(exc_traceback_obj) DeviceMmioBase = 0 print print "==== Sample 6. Dump VID, PID by _PciIoR32" from EfiPyLib.PciEmulate import _PciIoR32 for pcid in PciList: print "pci%s[0]: 0x%08X" % (pcid, _PciIoR32(pcid[0], pcid[1], pcid[2], 0)) print "pci%s[4]: 0x%08X" % (pcid, _PciIoR32(pcid[0], pcid[1], pcid[2], 4))
import EfiPyLib.Acpi.AcpiBgrt as AcpiBgrt if EfiPy.sizeof(AcpiBgrt.Table) != AcpiBgrt.Table.Header.Length: print 'WARNNING: size are not inconsisten: 0x%04X, 0x%04X' % (EfiPy.sizeof( AcpiBgrt.Table), AcpiBgrt.Table.Header.Length) print " Signature: %s" % struct.pack("I", AcpiBgrt.Table.Header.Signature) print " Length: 0x%08X" % AcpiBgrt.Table.Header.Length print " Revision: 0x%02X" % AcpiBgrt.Table.Header.Revision print " Checksum: 0x%02X" % AcpiBgrt.Table.Header.Checksum print " OemId: %s" % bytearray(AcpiBgrt.Table.Header.OemId) print " OemTableId: %s" % struct.pack("Q", AcpiBgrt.Table.Header.OemTableId) print " OemRevision: 0x%08X" % AcpiBgrt.Table.Header.OemRevision print " CreatorId: %s" % struct.pack("I", AcpiBgrt.Table.Header.CreatorId) print " CreatorRevision: 0x%08X" % AcpiBgrt.Table.Header.CreatorRevision print " Version: 0x%08X" % AcpiBgrt.Table.Version print " Status: 0x%08X" % AcpiBgrt.Table.Status print " ImageType: 0x%08X" % AcpiBgrt.Table.ImageType print " ImageAddress: 0x%08X" % AcpiBgrt.Table.ImageAddress print " ImageOffsetX: 0x%08X" % AcpiBgrt.Table.ImageOffsetX print " ImageOffsetY: 0x%08X" % AcpiBgrt.Table.ImageOffsetY print from EfiPyLib.EfiPyHexDump import EfiPyHexDump Memory = (EfiPy.CHAR8 * AcpiBgrt.Size).from_address(AcpiBgrt.Address) EfiPyHexDump(2, AcpiBgrt.Address, Memory, True, "ACPI: BGRT")
except: print " FACS %s: %s" % (_fName, getattr(AcpiFacs.Table, _fName)) print # # FACS dump, style two. # import struct print " AcpiFacs:Signature: %s" % struct.pack ("I", AcpiFacs.Table.Signature) print " AcpiFacs:Length: 0x%08X" % AcpiFacs.Table.Length print " AcpiFacs:HardwareSignature: 0x%08X" % AcpiFacs.Table.HardwareSignature print " AcpiFacs:FirmwareWakingVector: 0x%08X" % AcpiFacs.Table.FirmwareWakingVector print " AcpiFacs:GlobalLock: 0x%08X" % AcpiFacs.Table.GlobalLock print " AcpiFacs:Flags: 0x%08X" % AcpiFacs.Table.Flags if AcpiFacs.Revision >= 0x01: print " AcpiFacs:XFirmwareWakingVector: 0x%016X" % AcpiFacs.Table.XFirmwareWakingVector print " AcpiFacs:Version: 0x%02X" % AcpiFacs.Table.Version if AcpiFacs.Revision >= 0x02: print " AcpiFacs:OspmFlags: 0x%08X" % AcpiFacs.Table.OspmFlags import EfiPy if AcpiFacs.Size != EfiPy.sizeof (AcpiFacs.Table): print "WARNNING: FACS size and Spec defined size are inconsistent." print " FACS size: %d, Spec defined size: %d" % (AcpiFacs.Size, EfiPy.sizeof (AcpiFacs.Table)) print from EfiPyLib.EfiPyHexDump import EfiPyHexDump Memory = (EfiPy.CHAR8 * AcpiFacs.Size).from_address (AcpiFacs.Address) EfiPyHexDump (2, AcpiFacs.Address, Memory, True, "ACPI: FACS")