Skip to content

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

Closed
RyanTheTide wants to merge 3 commits into
mainfrom
usb/t8140-proxy-carrier-delay
Closed

RyanTheTide wants to merge 3 commits into
mainfrom
usb/t8140-proxy-carrier-delay

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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: 839 passed, 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.

Assisted-by: LLM (Claude:Opus 5.5)

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 RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No blockers in the code. The fix is correct and small. Before merge it needs the J700 run that the PR already lists under "Still to run". Unit tests alone don't show that the carrier comes up and the watchdog fires on the hardware.

What I checked: usb_init() against usb_cdc_state_schedule() (accepts 1000 to 15000 ms), usb_cdc_schedule() (arms the 170 s watchdog only on an accepted schedule), the callers (main.c:312 no-payload fallback, kboot.c skips usb_init() on this SoC, uartproxy.c:98 Stage 1 window), and how the poll loop picks the schedule up in uartproxy_run(). After this change the fallback proxy gets its carrier about 1 s in, through the same call the Stage 1 window already makes. With the window, the second schedule is skipped or refused without harm: by the time the window ends the state is READY or FAILED and the carrier is owned.

  1. src/usb.c:558, chip gate. This PR doesn't add the chip_id == T8140 check; the PR body says so, and that's right. The same check now decides "needs a deferred carrier transition" in six places: usb.c:558, usb_cdc.c:78 and :144, uartproxy.c:97, kboot.c and main.c:223 and :311. Follow-up, not for this PR: replace them with one predicate, like the existing usb_cdc_deferred_usb2(), that reads the DFU port's PHY or controller node in the ADT. That way the next SoC with this PHY gets the carrier and watchdog without a new gate. Fallback: today's behaviour when the property is missing.

  2. src/usb.c:560, the 1000. This is not a tuned delay. It's the floor of the validator's range, and the host-facing P_CDC_SCHEDULE needs a range so its reply goes out before the carrier changes. The local fallback has no requester, so the real intent is "as soon as allowed". The bug was a caller that drifted from the validator's literal range. A literal 1000 in usb.c and uartproxy.c:98 can drift the same way. Suggest a USB_CDC_SCHEDULE_MIN_MS (and MAX) in usb_cdc_state.h, used by usb_cdc_state_schedule(), proxy.c:507 and both callers. The test could then assert against the constant instead of parsing usb.c with a regex, which breaks on any reformat of that line. Not blocking.

  3. Out of scope, but on the path this PR enables: usb_cdc.c:123 mdelay(1000) after the HPM cold reset is a fixed settle wait. Please follow up with a bounded poll on the port controller's ready/mode state.

  4. Behaviour change worth stating in the commit message: with no payload and a non-enforcing policy, a T8140 Mac now resets about 170 s after the proxy comes up. Before, it stayed in the proxy. That matches what the Stage 1 boot watchdog already does, so it's fine. The panel text at main.c:288-290 only promises a restart when wdt_boot_watchdog_armed(), so a Stage 2 on this SoC now restarts without saying so. Optional: print the same "restarts by itself" line when the CDC watchdog armed. Note also that wdt_arm() restarts the counter, so this replaces a running 178 s boot watchdog with a fresh 170 s one. That's harmless.

Other chips: no change. The branch is T8140-only, and usb_cdc_schedule() refuses every non-T8140, non-USB2 target anyway. Production reach: this is not a lab-only path. It sits in the shipped Stage 1/Stage 2 no-payload fallback (#ifndef BRINGUP). It is reachable only when secboot_host_proxy_allowed() is true, so enforcing builds take the 10 s reboot instead. It never runs on a boot that hands off to an OS.

Evidence: unit tests and a build only. The 6-hour hang is linked to this path but, as the PR says, not proven. Hardware row: on J700 (A18 Pro), configure a dev Stage 2 whose payload is missing (not through aura-try, which reboots earlier since #436). Pass: no "usb: unable to schedule proxy transport", "CDC Gen1 ready; awaiting host" shows, the Mac resets about 170 s later and boots the configured path again; 3/3 runs. With a CDC host attached: "CDC primary open; watchdog disabled" and a proxy round-trip works; 3/3. Control on one non-T8140 Mac (M2 or M1 Pro): the same missing-payload fallback still brings up the normal USB proxy, unchanged.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Thanks. On the points:

  1. Agreed. The deferred-carrier predicate from the ADT is a follow-up, not part of this fix.
  2. Boot chain: wait on hardware state instead of fixed delays, and fail closed on ignored errors #416 already adds USB_CDC_SCHEDULE_MIN_MS/_MAX_MS in usb_cdc_state.h, and its window call uses them, but it leaves this call alone. Adding the same constants here would only conflict with it. Whichever lands second switches this literal to USB_CDC_SCHEDULE_MIN_MS, and the test then checks the constant (noted in the PR body).
  3. Noted as a follow-up: a bounded poll instead of the fixed mdelay(1000) after the HPM cold reset.
  4. The behaviour change (a host-less T8140 proxy now resets about 170 s in, replacing a running boot watchdog with a fresh 170 s one) is now stated in the PR body. The panel line is left for a follow-up.

The hardware row is as you describe; our Neo has no remote reset, so it waits for someone at the Mac, or a J700 with a CDC host.

Assisted-by: LLM (Claude:Opus 5.5)

@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.

Reviewed at 0838346907232e2e2905cc3f42ef968696406410 against the pre-PR checklist. Code, cross-SoC safety, Stage 2 size, tests, attribution, and CI are clean; holding APPROVE only for the §5 J700 hardware row.

Verified

  • USB proxy carrier scheduling logic: usb_init() (src/usb.c:558-563) previously passed delay_ms = 0 to usb_cdc_schedule(), which usb_cdc_state_schedule() (src/usb_cdc_state.c:9) unconditionally rejects (delay_ms < 1000 || delay_ms > 15000), preventing both the CDC carrier transition and usb_cdc_arm_watchdog() (170 s WDT at src/usb_cdc.c:81). Switching to 1000 uses the validator's minimum accepted delay (matching uartproxy_wait_stage1() at src/uartproxy.c:98) rather than a tuned magic sleep (§2).
  • Cross-SoC safety & Stage 1/2 size: Strictly confined to the existing chip_id == T8140 fallback branch (no new chip gate added, §1), and usb_cdc_schedule() rejects non-T8140/non-USB2 targets anyway. Zero behavioral change on M1/M2/M3/M4/M5 and never runs on normal OS handoffs or enforcing builds (secboot_host_proxy_allowed()). Immediate constant change (0 -> 1000) adds no code size; ESP stage 2 vital size and all 15/15 CI checks pass.
  • Tests: tests/python/test_t8140_proxy_transport.py exercises the real usb_cdc_state_schedule() / usb_cdc_state_due() against the arguments parsed from src/usb.c, verifies the delay=0 negative control, and checks that usb_cdc_schedule() arms the watchdog only on an accepted schedule.
  • §4 Attribution & §6 Naming: Commit 083834690723 has human author/committer and human Signed-off-by: with no AI commit trailers; PR body ends with Assisted-by: LLM (Claude:Opus 5.5). No §6 naming issues.

Owed before approval / merge

  • §5 Evidence (HW row): J700 (T8140) Stage 2 proxy-fallback run (outside aura-try):
    • No host attached: 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: prints CDC primary open; watchdog disabled and completes a proxy round-trip.
  • Non-blocking note: aurora-silicon/aura#416 is now closed; a follow-up can still introduce USB_CDC_SCHEDULE_MIN_MS/_MAX_MS in src/usb_cdc_state.h and replace the repeated chip_id == T8140 deferred-carrier checks with an ADT-driven predicate.

Assisted-by: LLM (Google:Gemini 4 Neon)

Aurora agent policy: remove assistant instruction files that are
not copies of .github/aurora/AGENTS.md on main, and keep the copies on policy
branches identical to it.
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Status of the J700 row: our Neo has no CDC host and no remote reset, so we can't run it unattended overnight. A failing run would leave the Mac sitting in the proxy until someone holds the power button. The image is built and the procedure is ready; it runs as soon as someone is at the Mac.

One thing that matters for whoever runs it: main already reboots a no-payload aura-try trial after 10 s (aura-try: the trial could not start its payload), before usb_init(). So a plain trial never reaches this PR's code. To exercise it through aura-try without writing a payload-less configured Stage 2, we use a lab-only patch on top of this head. The patch starts no payload and skips that 10 s trial reboot, and from there the shipped no-payload fallback runs: https://gist.github.com/RyanTheTide/eaee78ccc325023bf4751fbcab4e98d4 (LAB ONLY, never ships).

  • Without a host: pass if there's no usb: unable to schedule proxy transport, CDC Gen1 ready; awaiting host appears, and the Mac resets about 170 s after Running proxy... and comes back on the configured path. Without the PR (control), it stays in the proxy.
  • With your CDC host on the J700: pass if CDC primary open; watchdog disabled appears and a proxy round-trip works.
Build used here

aura main 6affb8e + this head c9f0977 + the lab patch. Release recipe (RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1), cross gcc, builds clean. Control image: the same without this PR. Base 6affb8e passed normal-path aura-try on our J700 three times on 11-22.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Besides the J700 row, the branch now needs main merged in: the only conflict is in AGENTS.md, CLAUDE.md, GEMINI.md and .github/copilot-instructions.md; keep main's copies.

@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.

Re-reviewed at c9f0977de46b8b7845e5f8487df54fdc689d8fdd against the pre-PR checklist (§1–§6).

Diff since prior review (08383469..c9f0977d)

  • There are no code or test changes since 083834690723 — src/usb.c and tests/python/test_t8140_proxy_transport.py are unchanged, and 08383469 itself merges cleanly into current main.
  • The only new commit is c9f0977de46b (gfya, authored and committed by github-actions[bot]), which deletes .github/copilot-instructions.md, AGENTS.md, CLAUDE.md, and GEMINI.md.

Blockers

  1. Merge conflict (DIRTY) & §4 commit hygiene (c9f0977d): main updated those four policy files in 6e1ac76745 (#428), so c9f0977d's deletions produce 4 modify/delete conflicts against main. c9f0977d is also bot-authored (github-actions[bot]) with no human Signed-off-by:. Please drop c9f0977d and rebase 08383469 onto main (keeping main's policy files without retaining the bot deletion commit in history).
  2. CI not run on current head: 0 CI checks have run on c9f0977d (last green CI was on 08383469). Full CI (build, test, format-check, stage1-size, esp-stage2-size) must run and pass on the rebased head.
  3. §5 Evidence (J700 HW row still owed): Noted your update that the J700 image and lab-only test procedure are staged and waiting for hands-on access to the Neo. Still required before merge:
    • Host-less J700 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 J700 run: prints CDC primary open; watchdog disabled and completes a proxy round-trip.

Checklist summary

  • §1 No model gating / §2 Production-ready / §3 Safety / §6 Naming: Clean on 08383469 (unchanged).
  • §4 Attribution: Blocked by bot commit c9f0977d; 08383469 and PR body disclosure are clean.
  • §5 Evidence: Pending J700 hardware row and fresh CI on the rebased head.

Assisted-by: LLM (Gemini 4 Neon)

An automated policy commit deleted AGENTS.md, CLAUDE.md, GEMINI.md and
.github/copilot-instructions.md on this branch after the policy file
changed on the default branch. Restore them as copies of its
.github/aurora/AGENTS.md so the branch merges cleanly again.

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

@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.

Re-reviewed at 7e430174cd3381e5efdbdcc44dc2a5f2051ba5c4 against the pre-PR checklist (§1–§6).

Resolved since prior review (c9f0977d..7e430174)

  • Merge conflicts (DIRTY -> MERGEABLE/CLEAN): Commit 7e430174cd33 restores .github/copilot-instructions.md, AGENTS.md, CLAUDE.md, and GEMINI.md to exact copies of main's .github/aurora/AGENTS.md. src/usb.c and tests/python/test_t8140_proxy_transport.py are unchanged from 083834690723.
  • CI (15/15 green): All 15 checks (policy x2, build, ESP stage 2 vital size, format-check, gcc, clang-macos, fedora, alarm, nix, and all 5 Pytest jobs) completed with SUCCESS on 7e430174.

Remaining blockers

  1. §4 Commit hygiene (c9f0977d still in branch history): c9f0977de46b (gfya, authored/committed by github-actions[bot] with no human Signed-off-by:) is still in the PR's commit list rather than dropped via rebase (7e430174 only restores the 4 files on top). Please rebase 08383469 onto main to drop c9f0977d + 7e430174 so no unsigned bot commit enters main on merge (unless squash-merged).
  2. §5 Evidence (J700 HW row still owed): No hardware run results have been posted yet (image and lab-only procedure remain staged awaiting hands-on J700/Neo access). Still required before merge:
    • Host-less J700 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 J700 run: prints CDC primary open; watchdog disabled and completes a proxy round-trip.

Checklist summary

  • §1 No model gating / §2 Production-ready / §3 Safety / §6 Naming: Pass (unchanged from 08383469).
  • §4 Attribution: 08383469, 7e430174, and PR body disclosure are clean; blocked only by retained unsigned bot commit c9f0977d in PR history.
  • §5 Evidence: CI 15/15 green; J700 hardware rows still owed.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #460: the same commit (0838346) on current main, without the unsigned bot commit and its revert. The J700 row procedure is unchanged and will be posted there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants