mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-09-21 05:31:53 +00:00
experiments/smc.py: Turn into SMC key dumper
Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
d381341865
commit
ec126bb16a
1 changed files with 25 additions and 5 deletions
|
@ -6,13 +6,15 @@ sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
from m1n1.setup import *
|
from m1n1.setup import *
|
||||||
from m1n1.fw.smc import SMCClient
|
from m1n1.fw.smc import SMCClient, SMCError
|
||||||
|
|
||||||
smc_addr = u.adt["arm-io/smc"].get_reg(0)[0]
|
smc_addr = u.adt["arm-io/smc"].get_reg(0)[0]
|
||||||
smc = SMCClient(u, smc_addr)
|
smc = SMCClient(u, smc_addr)
|
||||||
smc.start()
|
smc.start()
|
||||||
smc.start_ep(0x20)
|
smc.start_ep(0x20)
|
||||||
|
|
||||||
|
smc.verbose = 0
|
||||||
|
|
||||||
smcep = smc.epmap[0x20]
|
smcep = smc.epmap[0x20]
|
||||||
|
|
||||||
def gpio_key(pin):
|
def gpio_key(pin):
|
||||||
|
@ -21,7 +23,25 @@ def gpio_key(pin):
|
||||||
fourcc = 'gP' + ('00'+(hex(pin)[2:]))[-2:]
|
fourcc = 'gP' + ('00'+(hex(pin)[2:]))[-2:]
|
||||||
return fourcc
|
return fourcc
|
||||||
|
|
||||||
# Enable wifi/bluetooth
|
## Enable wifi/bluetooth
|
||||||
RFKILL_PIN = 13
|
#RFKILL_PIN = 13
|
||||||
smcep.write(gpio_key(RFKILL_PIN), struct.pack('<I', 0x800000 | 0x0))
|
#smcep.write(gpio_key(RFKILL_PIN), struct.pack('<I', 0x800000 | 0x0))
|
||||||
smcep.write(gpio_key(RFKILL_PIN), struct.pack('<I', 0x800000 | 0x1))
|
#smcep.write(gpio_key(RFKILL_PIN), struct.pack('<I', 0x800000 | 0x1))
|
||||||
|
|
||||||
|
count = smcep.read32b("#KEY")
|
||||||
|
print(f"Key count: {count}")
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
k = smcep.get_key_by_index(i)
|
||||||
|
length, type, flags = smcep.get_key_info(k)
|
||||||
|
if flags & 0x80:
|
||||||
|
try:
|
||||||
|
val = smcep.read_type(k, length, type)
|
||||||
|
print(f"#{i}: {k} = ({type}, {flags:#x}) {val}")
|
||||||
|
except SMCError as e:
|
||||||
|
print(f"#{i}: {k} = ({type}, {flags:#x}) <error {e}>")
|
||||||
|
else:
|
||||||
|
print(f"#{i}: {k} = ({type}, {flags:#x}) <not available>")
|
||||||
|
|
||||||
|
|
||||||
|
smc.stop()
|
||||||
|
|
Loading…
Reference in a new issue