"""Snapshot-diff the uproc control block across a host-injected PING. Run from the tool root: ./greeneye.sh run examples/scripts/dump_diff.py Demonstrates: symbol -> structure schema decoding, snapshot + diff, host stimulus via memory writes, and symbol-annotated output. """ import json from pathlib import Path from greeneye import Memory from greeneye.structs import render, schema_from_json TOOL_ROOT = Path(__file__).resolve().parents[2] schema = schema_from_json(json.loads((TOOL_ROOT / "firmware/uproc_demo/gsp_ctrl.schema.json").read_text())) ctrl = symbols.lookup("gsp_ctrl") # Let the firmware self-test settle. s.run(duration=0.4) before = s.snapshot(ctrl, schema.size, "ctrl-before-ping") # Host stimulus: PING with argument 0x1234. memory.write_u64(ctrl + 32, 1) # mailbox memory.write_u64(ctrl + 40, 0x1234) s.run(duration=0.4) after = s.snapshot(ctrl, schema.size, "ctrl-after-ping") print("decoded control block:") print(render(schema, schema.decode(after, base=ctrl))) print("\nchanged bytes:") print(Memory.render_diff(Memory.diff(before, after, base=ctrl), symbols))