From 66600dafc11edce89ff53e036e7a8c492c1acbdf Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 26 Sep 2026 10:24:10 +0000 Subject: [PATCH] Tap the touchscreen from --input-script The input script pressed POWER and the volume buttons only, so touch- driven payloads - Nyx above all - could not be driven headless. ` TAP [hold_ms]` touches the screen at (x, y) in the 1280x720 picture bdk's touch driver reports, inverted through its 15..1264 / 15..704 scaling to the FTS4 panel's raw coordinates, and lifts after hold_ms. The press and release go through the same event queue as a mouse click in the window. This is how Nyx's Tools > USB Tools > SD Card is reached headless: "12000 TAP 516 531, 15000 TAP 640 32, 17000 TAP 640 423, 19000 TAP 850 420, 22000 TAP 170 202" on hekate 6.5.3. The README now documents --input-script, which it did not mention before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb --- DESIGN.md | 6 +++++- README.md | 4 +++- input_script.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index df39c55..d3739b5 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -631,7 +631,11 @@ while (te_idx < n && state.emu_usec >= te_events[te_idx].at_us) { Because `emu_usec` is deterministic, the same timestamps land at the same UI states across runs. Adding a new automated flow is "press the buttons once -with `[input]` logging on, copy the timestamps". +with `[input]` logging on, copy the timestamps". `--input-script` does the +same for any payload without a rebuild (`input_script.cpp`): button presses +and touchscreen taps (` TAP `, in the 1280x720 picture, inverted +through bdk's touch scaling) keyed to `emu_usec`. That is how Nyx's USB tools +are reached headless. ## CCPLEX CPU0 diff --git a/README.md b/README.md index 5a1fe54..7f3a85d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ slow or destructive. [CCPLEX CPU0](#ccplex-cpu0). - Replay deterministic button sequences via `--auto-pin-recovery` or `--auto-te-script`, so a payload flow can be exercised from a CI run or a - one-shot script. + one-shot script. `--input-script` scripts buttons and touchscreen taps for + any payload. - Tweak emulated hardware live (battery, charger, thermal, USB-PD, PMIC, fuses, SD insertion) from a side window. See [Live hardware tweaks](#live-hardware-tweaks). - Inspect each Tegra UART port (TX history) and inject keystrokes into the @@ -278,6 +279,7 @@ needed. | `--oem` | `erista` \| `mariko` | Switch SoC generation. Drives `APB_MISC_GP_HIDREV` so Hekate's `h_cfg.t210b01` matches and pkg1 identification skips the right OEM header. Default `erista`. | | `--bt-radio` | `healthy` \| `faulty` \| `absent` | Broadcom CYW4356 behaviour on UART-D. `healthy` powers up on the `BT_REG_ON` edge, holds `BT_HOST_WAKE` high, asserts `RTS_N` and answers HCI; `faulty` reproduces the 2110-1118 console (module fitted, never leaves POR); `absent` additionally leaves `BT_UART_RXD` in a break condition. Overrides `[bluetooth] radio` in the ini. Default `healthy`. | | `--wifi-radio` | `healthy` \| `faulty` \| `absent` | The WLAN half of the same CYW4356: a PCI Express endpoint on root port 1, reachable only from CPU0 (the BPMP reads all ones, as on silicon). `healthy` trains the link, enumerates as `14E4:43EC` and answers a ChipCommon ChipID read with `0x4356`; `faulty` still trains and enumerates but reads all ones on the backplane (live PCIe front-end, dead radio die); `absent` never leaves detect. The model also enforces the datasheet's power-up ordering, so a payload that releases PERST# too early gets a link that stays down and a `[pcie]` line naming the reason. Overrides `[wifi] radio` in the ini. Default `healthy`. | +| `--input-script` | file or spec | Scripted input keyed to emulated time: ` P\|U\|D [hold_ms]` presses POWER / VOL+ / VOL-, ` TAP [hold_ms]` taps the touchscreen at (x, y) in the 1280x720 picture, `+N` times an event N ms after the previous one. Events are separated by `,`, `;` or newlines. | | `--auto-pin-recovery` | (none) | Drive the Lockpick PIN-recovery menu without user input. | | `--auto-te-script` | (none) | Drive `recover_pin.te` in TegraExplorer without input. | diff --git a/input_script.cpp b/input_script.cpp index b4a5692..163c174 100644 --- a/input_script.cpp +++ b/input_script.cpp @@ -12,6 +12,11 @@ // VOL_UP | VOLUP | UP | U // hold_ms how long to hold the button, default 200 ms. // +// TAP [hold_ms] +// +// touches the screen at (x, y) in the 1280x720 landscape picture bdk's +// touch driver reports (Nyx's coordinates), and lifts after hold_ms. +// // '#' starts a comment. Example - walk 6 entries down a menu and select: // // rcm_emu payload.bin --input-script "3000 D, + D, + D, + D, + D, + D, + P" @@ -27,6 +32,7 @@ #include "input_script.h" #include "emu_state.h" +#include #include #include #include @@ -36,7 +42,7 @@ namespace { -enum class Key { Power, VolUp, VolDown, Uart, UartFile }; +enum class Key { Power, VolUp, VolDown, Uart, UartFile, Tap }; struct Event { uint64_t at_us = 0; // press time @@ -45,6 +51,7 @@ struct Event { bool pressed = false; bool released = false; std::string data; // UART / UARTFILE payload + uint16_t x = 0, y = 0; // TAP: panel-raw coordinates }; std::vector g_events; @@ -60,6 +67,7 @@ const char *key_name(Key k) { case Key::VolUp: return "VOL+"; case Key::Uart: return "UART"; case Key::UartFile: return "UARTFILE"; + case Key::Tap: return "TAP"; default: return "VOL-"; } } @@ -80,6 +88,7 @@ bool parse_key(const std::string &tok, Key *out) { // UARTFILE pushes a file's raw contents, for binary protocol work. if (s == "UART") { *out = Key::Uart; return true; } if (s == "UARTFILE") { *out = Key::UartFile; return true; } + if (s == "TAP" || s == "T") { *out = Key::Tap; return true; } return false; } @@ -184,8 +193,24 @@ bool parse_text(const std::string &text) { continue; } - uint64_t hold_ms = (tok.size() >= 3) ? strtoull(tok[2].c_str(), nullptr, 10) - : kDefaultHoldMs; + size_t hold_tok = 2; + if (ev.key == Key::Tap) { + if (tok.size() < 4) { + fprintf(stderr, "[input-script] entry %d: expected ' TAP [hold_ms]'\n", + lineno); + return false; + } + // bdk's touch.c clamps raw samples to 15..1264 and 15..704 and + // stretches that span over 1280x720; invert it. + uint32_t x = std::min(strtoul(tok[2].c_str(), nullptr, 10), 1279); + uint32_t y = std::min(strtoul(tok[3].c_str(), nullptr, 10), 719); + ev.x = (uint16_t)(15 + (x * (1264 - 15) + 1279) / 1280); + ev.y = (uint16_t)(15 + (y * (704 - 15) + 719) / 720); + hold_tok = 4; + } + uint64_t hold_ms = (tok.size() > hold_tok) + ? strtoull(tok[hold_tok].c_str(), nullptr, 10) + : kDefaultHoldMs; if (hold_ms == 0) hold_ms = kDefaultHoldMs; ev.until_us = ev.at_us + hold_ms * 1000ULL; prev_release_us = ev.until_us; @@ -271,6 +296,30 @@ void input_script_tick(EmuState &state) { break; } + if (ev.key == Key::Tap) { + if (!ev.pressed && now >= ev.at_us) { + state.tc_pressed.store(true); + state.touch_post(0x03, ev.x, ev.y); // FTS4 ENTER + ev.pressed = true; + printf("[input-script] TAP down panel=(%u,%u) @%llu us (%zu/%zu)\n", + ev.x, ev.y, (unsigned long long)now, i + 1, g_events.size()); + fflush(stdout); + break; + } + if (ev.pressed && !ev.released && now >= ev.until_us) { + state.tc_pressed.store(false); + state.touch_post(0x04, ev.x, ev.y); // FTS4 LEAVE + ev.released = true; + if (i == g_done) { + g_done++; + if (g_done == g_events.size()) + printf("[input-script] sequence complete\n"); + } + } + if (!ev.released) break; + continue; + } + std::atomic *btn = (ev.key == Key::Power) ? &state.btn_power : (ev.key == Key::VolUp) ? &state.btn_vol_up : &state.btn_vol_down;