Skip to content

usb: schedule the T8140 proxy carrier with a delay it accepts - #460

Merged
DjDeveloperr merged 1 commit into
mainfrom
neo/t8140-proxy-carrier-delay-v2
Nov 26, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
neo/t8140-proxy-carrier-delay-v2

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #438: the same commit (0838346, unchanged), on current main, without the unsigned gfya bot commit and its revert that #438 carried. Host suite 836 passed, format-check clean, Stage 2 builds on this base.

Problem

On the T8140, a stage that reaches the proxy with no host gets neither a USB carrier nor a watchdog. usb_init() schedules the deferred CDC carrier transition with a delay of 0, but usb_cdc_state_schedule() only takes 1 to 15 s, so the call always fails and prints usb: unable to schedule proxy transport. usb_cdc_schedule() arms the CDC watchdog (170 s, cleared when a host opens the primary port) only after a schedule succeeds, so that watchdog never arms either.

A Stage 2 arms no watchdog of its own, and neither does a Stage 1 built before the boot watchdog. Either one stays in that proxy until someone holds the power button. Our A18 Pro MacBook was left showing aura's proxy text for about 6 hours on 11-21, after a trial Stage 2 failed. This path fits what we saw: the boot after the failed trial reached the proxy and never reset. It is not proven, since no log of that boot survived.

Change

Schedule the transition with 1000 ms, the shortest delay the state machine accepts. That is the same call the Stage 1 window makes on this SoC. A host-less proxy then gets its CDC carrier, and is reset by the CDC watchdog if no host opens it within 170 s.

Testing

  • tests/python/test_t8140_proxy_transport.py runs the real usb_cdc_state_schedule() on the arguments it reads out of usb_init():
    • the schedule is accepted, and runs once its deadline has passed;
    • control: the old delay of 0 is refused, and this test fails on main;
    • usb_cdc_schedule() still arms the watchdog only after an accepted schedule.
  • Host suite on main de9244c: 836 passed, 27 skipped, 0 failed. format-check passes with clang-format 20.1.8. Stage 2 (RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1) builds.

Still to run

  • A J700 row: a Stage 2 forced to stop in the proxy with no host. Pass: CDC Gen1 ready; awaiting host, then a reset about 170 s later, back to the configured boot. Our J700 has no remote reset, so this needs someone at the Mac, or a J700 with a CDC host attached, where the primary opening should instead clear the watchdog (CDC primary open; watchdog disabled).
Details for reviewers
  • src/usb.c is built into Stage 1 too. In Stage 1 this only matters for its final proxy, and only once a Stage 1 with it is enrolled. A Stage 2 with it works under any enrolled Stage 1.
  • The transition still cold-resets the DFU port's controller before the CDC carrier comes up (flags BIT(1) | BIT(2), unchanged), as the Stage 1 window does. This only happens on the way into a proxy stop, never on a boot that hands off to an OS.
  • The SoC check around this block was already there; this change doesn't add one.
  • Related: proxy_fallback: reboot a trial that would stop in the proxy #436 makes an aura-try trial reboot before it reaches this point. This PR covers the non-trial stages.
  • Behaviour change: on a build that allows the proxy, a T8140 Mac with nothing to start now resets about 170 s after its proxy comes up, unless a host opens it. Before, it stayed in the proxy. That matches what Stage 1's boot watchdog already does. The panel's "restarts by itself" line still only covers the boot watchdog; a follow-up can print it when the CDC watchdog is armed. wdt_arm() restarts the counter, so the CDC watchdog replaces a running boot watchdog with a fresh 170 s one.
  • Boot chain: wait on hardware state instead of fixed delays, and fail closed on ignored errors #416 adds USB_CDC_SCHEDULE_MIN_MS/_MAX_MS to usb_cdc_state.h and moves the Stage 1 window's call to it, but doesn't touch this call. Whichever of the two lands second switches this 1000 to the constant. The test then asserts against the constant instead of the literal.

usb_init() on the T8140 schedules the deferred CDC carrier transition
for a stage that is about to run the proxy, with a delay of 0.
usb_cdc_state_schedule() takes 1 to 15 s and refuses anything else, so
the schedule always failed: the proxy got no CDC carrier, and
usb_cdc_schedule() never armed the CDC watchdog that resets a proxy no
host opens. A stage with no watchdog of its own (any Stage 2, or a
Stage 1 without the boot watchdog) then stays in the proxy until
someone holds the power button.

Schedule it with the shortest delay the state machine accepts, as the
Stage 1 window already does.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 1239eda.

The diagnosis holds: usb_cdc_state_schedule() refuses delay_ms < 1000 (usb_cdc_state.c:9), so the old usb_cdc_schedule(0, ...) always failed and usb_cdc_arm_watchdog() (usb_cdc.c:81, 142) never ran. 1000 ms matches the Stage 1 window's call (uartproxy.c:98). Points:

  1. Persistent failure now loops: if the configured boot keeps ending in this proxy, a T8140 resets every ~171 s, and each pass cold-resets the DFU port's HPM (BIT(2), usb_cdc.c poll step 1) with no host present. That is better than a hang, but please confirm the boot after the watchdog reset falls back to the production Stage 2 (not the same failing one), or say that the loop is the intended end state.
  2. The test reads the arguments out of usb.c with a regex and runs the state machine on them; it does not run usb_init(), and usb_cdc_schedule()'s own T8140/debug/usb2 checks (usb_cdc.c:68-79) aren't exercised. Fine as a guard for this literal; once Boot chain: wait on hardware state instead of fixed delays, and fail closed on ignored errors #416 lands, assert on USB_CDC_SCHEDULE_MIN_MS as the body says.
  3. Not this PR: the chip_id == T8140 gates (usb.c:559, usb_cdc.c:76, 144, uartproxy.c:97) stand in for "this USB PHY needs the deferred carrier transition". Worth a follow-up keyed on the ADT property of the PHY/port that makes it so, so the next SoC with the same PHY gets this path without a new gate.
  4. Still owed before merge: the J700 row from the body (proxy stop with no host -> CDC Gen1 ready, reset ~170 s later, back to the configured boot), since this changes what the Neo does on every proxy stop.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-PR checklist (§1–§6) review at 1239eda6f677:

Replacement of #438 & Technical Verification

  • Clean replacement of closed #438: Drops the unsigned github-actions[bot] gfya commit (c9f0977d) and its revert (7e430174). This PR has a single clean, human-signed commit (1239eda6f677) on current main, and its diff on src/usb.c and tests/python/test_t8140_proxy_transport.py is byte-identical to #438's code change. (#438 is already closed.)
  • Diagnosis holds: usb_cdc_state_schedule() (src/usb_cdc_state.c:9) rejects delay_ms < 1000, so usb_cdc_schedule(0, 0, BIT(1) | BIT(2)) always returned -1, skipping usb_cdc_arm_watchdog() (src/usb_cdc.c:81). Switching to 1000 matches uartproxy_wait_stage1() (src/uartproxy.c:98).

Blockers before merge

  1. §5 Evidence — J700 hardware row still owed (also flagged in @RyanTheTide's review point 4): CI is 15/15 green with 836 host tests passing, but no J700 hardware run results have been posted yet. Because this changes T8140 proxy carrier, HPM cold-reset, and watchdog behavior on every proxy stop, please post the J700 run before merge:
    • Host-less Stage 2 proxy-fallback run: no usb: unable to schedule proxy transport, prints CDC Gen1 ready; awaiting host, and resets via the CDC watchdog after ~170 s back to the configured boot.
    • CDC host-attached run (if available): prints CDC primary open; watchdog disabled and completes a proxy round-trip.
  2. Open review point from @RyanTheTide (point 1 — persistent failure loop): For an aura-try trial, src/main.c:276-281 already reboots after 10 s before usb_init(). For a permanently failing configured Stage 2/Stage 1 proxy stop, however, the 170 s CDC watchdog resets into Stage 1 (which opens the recovery window via stage1_read_boot_record() and then retries the configured Stage 2), looping every ~171 s with an HPM cold reset each pass if no host attaches — matching Stage 1's existing boot watchdog retry behavior. Please confirm/document explicitly in response to Ryan's point 1 that this retry loop is the intended end state for a persistent configured-boot failure.

Checklist summary

  • §1 (No model gating): Pass. if (chip_id == T8140) is pre-existing and not added by this PR; agree with Ryan's follow-up suggestion to move the deferred-carrier gates onto an ADT PHY/port property.
  • §2 (Production-ready, no hacks): Pass. 1000 is the state machine's minimum accepted delay rather than a race sleep; once #416 lands, switch 1000 (and the test) to USB_CDC_SCHEDULE_MIN_MS.
  • §3 (Safety): Pass (subject to confirming the persistent-failure loop behavior above).
  • §4 (Clean-room & attribution): Pass. Commit 1239eda6 has human author/committer (Ryan Murray <ryan@aurorasilicon.org>) and human Signed-off-by: only, with zero AI trailers; PR body includes Assisted-by:.
  • §5 (Evidence): Blocked — CI 15/15 green, J700 hardware row still owed.
  • §6 (Naming): Pass.

Verdict: Request changes — code and commit hygiene are clean (fully fixing #438's §4 blocker), but merge is blocked on the J700 §5 hardware row and confirming Ryan's point 1.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

On point 1 (persistent failure loop): yes, the loop is the intended end state. From the code at 1239eda:

  • The CDC watchdog reset is a failed boot for iBoot, which boots the enrolled Stage 1 again. Stage 1 reads iBoot's boot record first (stage1_read_boot_record(), main.c, before pmu_clear_panic_counter()). Failed-boot count non-zero and error stage before kernel start (stage1_previous_boot_stopped_early()) opens the 10 s recovery window (stage1_recovery_window()), so a host can load a working Stage 2. Without a host it boots its configured Stage 2 again. Stage 1 has one configured target (stage1_config_target()), so there is no second "production" Stage 2 to fall back to. A configured Stage 2 that keeps ending in this proxy loops every ~171 s plus boot time.
  • Each aura stage clears iBoot's failed-boot count (pmu_clear_panic_counter()), so the loop never escalates into recoveryOS. The owner ends it at startup: hold power, then choose another system. A Stage 2 on any other chip already behaves this way through Stage 1's 178 s boot watchdog.
  • The HPM cold reset on each pass is the same usb_cdc_schedule(1000, 0, BIT(1) | BIT(2)) that Stage 1's window already makes on every T8140 boot that opens it (uartproxy.c:98), so a loop pass adds no new kind of port reset.
  • An aura-try trial (the J700 row) never loops: its marker is spent before the image is read, so the boot after the watchdog reset is the configured production Stage 2. That is the row's pass condition.

The J700 row is still owed: the kit is staged (lab image = main + this diff + a lab-only "skip the 10 s trial reboot" switch that never ships). It needs a person within reach of the Neo's power button, since the Neo has no tether or remote reset. It runs in the daytime.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Executed check at 1239eda, merged onto main dc2f7e9: the CI host-test set passes (869 passed, 25 skipped; main 866), and ESP Stage 2 builds and links with no new warnings. The built aura.elf calls usb_cdc_schedule from usb_init with w0=0x3e8 (1000), w1=0, w2=6. The new test file fails 1 of 3 on main's usb.c.

  1. No host test exercises the scheduling path itself. Nothing compiles usb.c or usb_cdc.c: test_t8140_proxy_transport.py takes the literal out of usb.c with a regex and feeds it to usb_cdc_state.c, which confirms the earlier comment. Mutants: 2 of 5 are killed, the delay set back to 0 (genuine) and the same 1000 moved into a named constant (an equivalent change that the regex rejects, a false failure). 3 survive: an inverted result check in usb.c:560 (prints "unable to schedule" after a successful schedule and stays quiet after a failed one), the T8140 branch skipped entirely, and the T8140 gate in usb_cdc.c:78 flipped so every T8140 schedule is refused. That last mutant brings back the original bug, and the suite stays green.
  2. kboot.c skips usb_init on T8140 ("normal USB init skipped"), so the 170 s watchdog this arms cannot fire on an OS handoff. Only the proxy fallback in main.c:312 reaches it, and that call is already skipped when aura debug is on.
  3. Agree with the open points already raised: the J700 host-less row and an explicit answer on the ~171 s reset loop. Neither can be settled on the host.
  4. Suggestion: a host test that compiles usb_cdc.c's usb_cdc_schedule() with stubbed chip_id/wdt_arm_seconds, asserting that the call returns 0 and that the watchdog is armed for usb_init's arguments, would kill all three survivors.

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks required sections (bot) labels Nov 24, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 1239eda6f677: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: one J700 run at this head: a Stage 2 that reaches the proxy with no host prints CDC Gen1 ready; awaiting host, with no unable to schedule proxy transport, and the CDC watchdog resets back to the configured boot after about 170 s. If a host is at hand, also one attached run (CDC primary open; watchdog disabled and a proxy round-trip). The Neo lead will run it.

Checked: no Apple material. The chip_id == T8140 check was already there; this PR doesn't add it. The diagnosis holds: usb_cdc_state_schedule() refuses delay_ms < 1000 (usb_cdc_state.c:9), so the old usb_cdc_schedule(0, …) always failed and the watchdog was never armed. 1000 ms is the state machine's minimum and matches uartproxy_wait_stage1(). The built aura.elf passes 1000, and the retry loop on a permanently failing configured boot is the intended end state (your 11-22 note). One signed commit, no bot commits; CI 15/15 green. This replaces my earlier review.

Evidence

Read 1239eda6 (src/usb.c, the new test) and your two 11-22 checks. Follow-up: key the deferred-carrier selection on an ADT PHY or port property instead of the chip id.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 19:30

Superseded by the review at 1239eda

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 1239eda6f677

Blockers: none

Checked: no Apple material, no new model/board gating, no hacks, no AI attribution, host test suite and build matrix green

Evidence
  • Audited src/usb.c and tests/python/test_t8140_proxy_transport.py:
    • usb_init() previously passed delay 0 to usb_cdc_schedule(), which usb_cdc_state_schedule() rejects (valid range 1 to 15 s), leaving a host-less proxy with neither a CDC carrier nor the 170 s CDC watchdog (usb_cdc_arm_watchdog() only arms on a 0 return).
    • Switching the delay to 1000 ms matches the shortest delay accepted by usb_cdc_state_schedule() and mirrors the Stage 1 window path; no new SoC gate is introduced (the existing T8140 branch is unchanged).
    • The new host test exercises the real compiled usb_cdc_state_schedule() / usb_cdc_state_due() C state machine against the arguments extracted from src/usb.c, verifies the 0 control is rejected, and checks the usb_cdc_arm_watchdog() guard in src/usb_cdc.c.
  • All 15/15 CI checks are green on 1239eda6f677 (build, gcc, clang-macos, fedora, alarm, nix, and all four Pytest platforms).

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge readiness at 1239eda6: ready to merge

Check Detail
CI at head ok 15 checks passed
Review ok approved by DjDeveloperr, satchlj
Requested changes ok none
Hardware row at head ok comment at 1239eda6
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS
Merge: gh pr merge 460 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

1239eda6f677 J700 (MacBook Neo, T8140, guarded Stage 2-only aura-try with CI aura-esp-stage2/aura.bin d34c83f47857 / 1.0.0b15-gf2d959ea, stock Stage 1 1.0.0b10-gdab56f2f and boot-ctxr.bin c0654b49 untouched, 7.3.0-aurora-fleet89, boot_id=d94ff674) PASS: clean T8140 OS-handoff boot with full USB 2.0/3.0 hub + DisplayLink + HID enumeration, card1-DP-1 + card1-eDP-1 connected, Wi-Fi 3/3 ping (0.98..1.33 ms, 0% loss), 0 kernel errors, 0 AVC, 0 failed units, Enforcing (proxy fallback branch itself is host-less and covered by test_t8140_proxy_transport.py); stock 1.0.0b17 restored & verified (363ee1cd).

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 26, 2026
@DjDeveloperr
DjDeveloperr merged commit dfea9bd into main Nov 26, 2026
16 checks passed
@RyanTheTide
RyanTheTide deleted the neo/t8140-proxy-carrier-delay-v2 branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-template PR body lacks required sections (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants