1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
"""RETEST: previous run never satisfied the gate.
asd_encoder_query reaches asd_encoder_state_check only when:
entry+40 == 0x30 (host: a2[32])
entry+32 != 0 (host: a2[24])
then passes entry+20 (host: a2[12]) as the UNBOUNDED index into 0xD42660+3*a1+2.
asd_topology_update mapping (a2 = the 0x40-byte struct):
a2[0]->entry+8 a2[4]->+12 a2[8]->+16 a2[12]->+20 a2[16]->+24
a2[20]->+28 a2[24]->+32 a2[28]->+36 a2[32]->+40
In our DTM frame the struct starts at buf+0x14, so field[i] = a2[4*i]:
field3 -> entry+20 (INDEX) field6 -> entry+32 (!=0) field8 -> entry+40 (==0x30)
"""
import ctypes,struct,sys
from tinygrad import Device
from tinygrad.runtime.autogen.am import am
from tinygrad.helpers import lo32,hi32
d=Device["AMD"]; adev=d.iface.dev_impl; psp=adev.psp
SZ=ctypes.sizeof(am.struct_psp_gfx_cmd_resp); P='/Users/user/dev/amd-psp-re/psp_out/'; S=0x8000
def stat(): return int.from_bytes(bytes(adev.vram.view(psp.cmd_paddr,SZ)[:])[864:868],"little")
def alloc(n):
pa=adev.mm.palloc(n,align=0x1000,zero=True); return pa,adev.paddr2mc(pa)
def load(cmd,blob):
ap,amc=alloc(0x40000); cp,cmc=alloc(S)
adev.vram.view(ap,len(blob))[:]=blob; adev.gmc.flush_hdp()
adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ
c=am.struct_psp_gfx_cmd_resp(cmd_id=cmd); t=c.cmd.cmd_load_ta
t.app_phy_addr_hi,t.app_phy_addr_lo=hi32(amc),lo32(amc); t.app_len=len(blob)
t.cmd_buf_phy_addr_hi,t.cmd_buf_phy_addr_lo=hi32(cmc),lo32(cmc); t.cmd_buf_len=S
return psp._ring_submit(c).resp.session_id, cp
def inv(sid,shm,buf,tc):
adev.vram.view(shm,S)[:]=bytes(buf); adev.gmc.flush_hdp()
adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ
ic=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_INVOKE_CMD); iv=ic.cmd.cmd_invoke_cmd
iv.session_id,iv.ta_cmd_id=sid,tc
try: psp._ring_submit(ic); ps=0
except RuntimeError: ps=stat()
except TimeoutError: return "TIMEOUT",None
return ps, bytes(adev.vram.view(shm,S)[:])
asd,_=load(am.GFX_CMD_ID_LOAD_ASD,open(P+'asd_full.bin','rb').read())
dtm,dsh=load(am.GFX_CMD_ID_LOAD_TA,open(P+'dtm_full.bin','rb').read())
hdcp,hsh=load(am.GFX_CMD_ID_LOAD_TA,open(P+'hdcp_full.bin','rb').read())
print("sids asd=%#x dtm=%#x hdcp=%#x MEMSIZE=%s"%(asd,dtm,hdcp,hex(adev.rreg(0xde3))))
def topo(h, f):
b=bytearray(S); struct.pack_into('<I',b,0,2)
struct.pack_into('<%dI'%(1+len(f)),b,0x10,h,*f)
ps,o=inv(dtm,dsh,b,2)
return (ps, struct.unpack_from('<I',o,8)[0] if o else None)
def hc(c,slot=0):
b=bytearray(S); struct.pack_into('<I',b,0,c); struct.pack_into('<I',b,0xC,slot)
ps,o=inv(hdcp,hsh,b,c)
return (ps, struct.unpack_from('<I',o,4)[0] if o else None)
def health(): return psp.is_sos_alive(), hex(adev.rreg(0xde3))
def mkf(idx, gate=True):
f=[1,1,0,0,0,0,0,0,0]
f[3]=idx # entry+20 : the unbounded index
if gate:
f[6]=1 # entry+32 != 0
f[8]=0x30 # entry+40 == 0x30
return f
print("\n%-12s %-10s %-8s topo 0x0E 0x10 0x12 health"%("index","addr","gate"))
for gate in (False,True):
for idx in (0,8,9,186,0x1000,0x100000,0x10000000,0x55555555):
addr=0xD42660+3*idx+2
f=mkf(idx,gate)
t=topo(0,f)
r0=hc(0x0E); r1=hc(0x10); r2=hc(0x12)
a,m=health()
flag=""
if not a or m!='0x5ff0' or "TIMEOUT" in (str(r0[0]),str(r1[0]),str(r2[0])): flag=" <<<< FAULT"
print(" %-10d %#011x %-8s %-9s %-15s %-15s %-15s %s %s%s"%(idx,addr&0xffffffff,gate,t[1],r0,r1,r2,a,m,flag))
if flag: print(" !! FAULT -- stopping"); sys.exit(2)
print("\nfinal health:",health())
|