#!/usr/bin/env python3 """Load the ASD driver and run it, through the path hardware actually uses. ASD is NOT loaded by the boot-time staging sweep, and that is correct firmware behaviour rather than an emulator gap. `bl_stage2_task` guards its staging slot (`+0x6F8000`) with a runtime flag: 00204a32 ldr r0, [r4, #4] 00204a34 ldr.w r0, [r0, #0x3e8] 00204a38 cmp r0, #0 00204a3a bge 0x204a76 ; >= 0 -> skip the ASD load entirely ... 00204a46 mov.w r2, #0x30000 ; slot bound 00204a54 add.w r1, r1, #0x6f8000 00204a58 bl 0x203f24 ; bl_load_ta_image The gate field (VA 0x20E3E8) is **never written** during boot -- measured with a write hook over the whole boot, zero writes -- so it keeps its zeroed BSS value and the branch is always taken. ASD is driver-class (`'DR'` = 0x5244 at body+0x14), not a TA, and arrives at runtime through the host ring instead. So: boot, initialise the ring, and hand ASD to the firmware's own loader the same way a host driver does. The image is verified on the CCP model (1 RSA operation) and then executes in its own address space at 0xD00000. Controls, because "ASD ran" is only meaningful if it could have failed: positive -- clean image executes ASD code; negative -- one bit flipped in the signed body, and one in the signature, must each yield ZERO executed ASD blocks. Exits non-zero unless all three hold. """ import sys, os, struct, importlib.util sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.dirname(__file__)) import unicorn from unicorn import UC_HOOK_BLOCK _b = importlib.util.spec_from_file_location( "bmmod", os.path.join(os.path.dirname(__file__), "boot_and_mailbox.py")) BM = importlib.util.module_from_spec(_b); _b.loader.exec_module(BM) M = BM.M ASD_LO, ASD_HI = 0x00D00000, 0x00E00000 # ASD's own address space TA_PA = 0x04400000 # host-side staging for the image IMAGE = os.environ.get("ASD_IMAGE", "asd_full.bin") def boot_with_ring(): """Boot sOS, bring up the command ring. No TA loaded yet.""" c, ccp, irqs, exc = BM.build() run, _ = M.make_det_runner(c, irqs) BM.drain_until( run, lambda: int.from_bytes(c.uc.mem_read(M.RING_STATUS, 4), "little") == 0x80000000, slices=12, blocks=500_000) M.install_debug_gpio(c) box = M.Mailbox(c, irqs) c.uc.mem_write(BM.RING_PA, b"\x00" * BM.RING_SZ) rp = bytearray(0x1C) rp[0x10:0x14] = struct.pack("