#!/usr/bin/env python3 """One-shot NON-ROP FE0A mapping discriminator on the card. No FE0A selector-4 chosen writes, no GCP pivot, no LSDMA/MP1-MMU writes. An in-buffer diagnostic FE0A control first checks all gates; ONE subsequent out-of-buffer comparator may fault if the params VA differs from BOTH bases. Both FE0A paths may emit three ASD->SYS_DRV 0x1079 events to MP1 PMI3. On ring timeout stop and recover with ATX. """ import ast import glob import hashlib import json import os import struct import sys from tinygrad import Device import tinygrad.runtime.autogen.am.am as am # Reuse ONLY the pure AES/CMAC definitions from the byte-identical older probe. # Parse as DATA: never import or execute its top-level card-operation code. HELPER = '/root/psp/hw/gcp_fe0a_sel8_probe.py' EXPECTED_SHA256 = '7e0a36457d7841e027d94ca42742ab5702e325b6ce719d1e261149173d9e64a9' src = open(HELPER, 'rb').read() assert hashlib.sha256(src).hexdigest() == EXPECTED_SHA256 nodes = [] for node in ast.parse(src.decode()).body: if isinstance(node, ast.Assign) and len(node.targets) == 1 and isinstance(node.targets[0], ast.Name) and node.targets[0].id == 'SB': nodes.append(node) if isinstance(node, ast.FunctionDef) and node.name in ('xt', 'expand', 'enc', 'dbl', 'cmac'): nodes.append(node) assert len(nodes) == 6 and {n.name for n in nodes if isinstance(n, ast.FunctionDef)} == {'xt','expand','enc','dbl','cmac'} helper = {} exec(compile(ast.fix_missing_locations(ast.Module(body=nodes, type_ignores=[])), HELPER, 'exec'), helper) cmac = helper['cmac'] g = json.load(open('/root/psp/hw/fe08_good.json')) ct, sk, seedoff = bytes.fromhex(g['ct']), bytes.fromhex(g['sk']), g['seedoff'] assert cmac(sk, bytes([1,0,0,0])+bytes(range(4,0x20))).hex() == g['mac'] print('CMAC self-test OK; key material not printed', flush=True) BUFLEN, PAT = 0x40000, 0xA5 DISP, SEED = 0xFC3E0A60, 0x40000001 assert ((0x04024000 + 0x14 + DISP) & 0xffffffff) == 0x404A74 assert ((0x04035000 + 0x14 + DISP) & 0xffffffff) == 0x415A74 # One-shot guard against accidentally replaying this stateful test. marker = '/root/psp/hw/.gcp_fe0a_params_va_nonrop.attempted' fd = os.open(marker, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600) os.close(fd) adev = Device['AMD'].iface.dev_impl psp = adev.psp def alloc(n): pa = adev.mm.palloc(n, align=0x1000, zero=True, boot=False) return pa, adev.paddr2mc(pa) def submit(cmd): return psp._ring_submit(cmd) def load(blob, which, app_pa, app_mc, cmd_mc, cmdlen): n = (len(blob)+3)&~3 adev.vram.view(app_pa,n)[:] = blob + b'\0'*(n-len(blob)) adev.gmc.flush_hdp() c = am.struct_psp_gfx_cmd_resp(cmd_id=which) t = c.cmd.cmd_load_ta t.app_phy_addr_lo,t.app_phy_addr_hi = app_mc&0xffffffff,app_mc>>32 t.app_len = len(blob) t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi = cmd_mc&0xffffffff,cmd_mc>>32 t.cmd_buf_len = cmdlen r = submit(c) return r.resp.status&0xffffffff,r.resp.session_id asd_app,asd_mc = alloc(0x80000) asd_cmd,asd_cmd_mc = alloc(0x10000) app,app_mc = alloc(0x80000) cmd,cmd_mc = alloc(BUFLEN) asd_blob = open('/root/psp/contall/asd_33-0-0-163_18debcc4.bin','rb').read() gcp_blob = open(glob.glob('/root/psp/contall/ta_22-0-0-77*')[0],'rb').read() a_status,_ = load(asd_blob, am.GFX_CMD_ID_LOAD_ASD, asd_app, asd_mc, asd_cmd_mc, 0x10000) print('ASD load status=%#x'%a_status, flush=True) assert a_status == 0 status,sid = load(gcp_blob, am.GFX_CMD_ID_LOAD_TA, app, app_mc, cmd_mc, BUFLEN) print('GCP load status=%#x sid=%s'%(status,sid), flush=True) assert status == 0 and sid def build(op,handle,blob=None,seed=None,extra=None): b = bytearray([PAT])*BUFLEN struct.pack_into('