-
Notifications
You must be signed in to change notification settings - Fork 75
Python UEFI Samples
This wiki page provides sample code to use Python UEFI provided capabilities to interact with the underlying UEFI platform. Use Python UEFI to read certain platform registers such as PCIe configuration space, Module Specific Registers (MSRs), IO Port registers, MMIO registers, CPUIDinstructions execution and etc.
Executing CPUID Instructions:
Python UEFI has a built in module known as edk2 module which provides APIs to perform the basic register read/write operations.
Signature of cpuid function: cpuid(eax, ecx) -> (eax, ebx, ecx, edx) Depending on the input values EAX and ECX the cpuid function returns different information about the processor.
- The following code snippet demonstrates how to read the CPUID of the given platform from UEFI shell using Python script. import edk2
eax=0x01 ecx=0x00 x=edk2.cpuid(eax, ecx) print(hex(x[0]))
- The following code snippet demonstrates how to read vendor id string of the given platform from UEFI shell using Python script.
import edk2
def hex2bytes(data): b=bytearray() for count in range(4): d = data & 0xff b.append(d) data = data >> 8 return b
eax=0x00 ecx=0x00 x=edk2.cpuid(eax, ecx)
data = hex2bytes(x[1])
data += hex2bytes(x[3])
data += hex2bytes(x[2])
print(data) vendor_string = [chr(item) for item in data]
print("Vendor String = {}".format(vendor_string))