Skip to content

Boot chain: wait on hardware state instead of fixed delays, and fail closed on ignored errors - #441

Closed
RyanTheTide wants to merge 32 commits into
mainfrom
hack/stack-rebase2-20261122
Closed

RyanTheTide wants to merge 32 commits into
mainfrom
hack/stack-rebase2-20261122

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #416, rebased onto current main (conflicts in src/kboot.c: main's dt_set_aop_firmware() now keeps the AOP node offset and preserves locked-DART firmware mappings first; the AOP-disable commit keeps that check and looks the node up again after the reservation edits the tree, and the later dt_disable_aop() commit replaces that lookup as before).

Replaces #368, rebased onto current main (conflicts in src/usb.c: the register defines still move to usb_atc_regs.h, main's usb_adt_node_path() kept; src/kboot.c: main's dt_find_aop() rework dropped the node local the AOP-disable commit used, so that commit now declares it).

Boot-chain fixes from a sweep for fixed waits, ignored errors and unnamed constants. Each commit stands alone; they are stacked in one PR to keep review and CI in one place. Summary:

  • rtkit: wait for the coprocessor's stop bit, not a fixed 1 ms
  • kboot: refuse a trial payload whose watchdog U-Boot would take over
  • kboot: disable the T6040/T6041 AOP when its firmware segments are not reserved
  • sptm_virt: call AURA_TRAP_DELAY_NS a diagnostic
  • tps6598x: wait for the HPM firmware after a reset instead of fixed sleeps
  • usb: name the CDC schedule flags and the ATC USB2 PHY/PIPE fields
  • pcie: poll endpoint config readiness, PERST#/refclk timing from the ADT
  • pcie: stop the ANS power-off if a PHY clock does not drop
  • j873: poll for the eUSB2 PHY's UTMI clock
  • kboot: whole speaker amp group configuration or none
  • dptx-phy (T8152): fail activation when impedance calibration does not complete or the PHY node is missing
  • dcp (T8152): name the ATC and dptx-phy settle delays, drop one duplicated wait; name the IOReturn codes; describe the ATC steps without driver-internal names
  • tests/ci: fix the T6030 display host test (stopped linking) and run the eight host tests that need no Mac files in CI

Testing (all commits)

  • This rebase, locally: make format-check (clang-format 20.1.8) and make rustfmt-check clean; clang builds of Stage 1 and the ESP Stage 2 and both esp-stage2-size configs OK (ESP vital region 745480 B of 1179648 B); pytest tests/python + T8122 tests 843 passed, 27 skipped (gcc), 842 passed, 28 skipped (USE_CLANG=1); tests/python/test_tps6598x_command.py 8 passed; the seven CI host tests plus t8122-gpu26-identity pass with gcc and clang (kboot audio 28 scenarios, DT-full 116 whole / 13 none), M3 start.S move gate pass under qemu, run-pmp-boot-data.sh OK. GCC 16 here still cannot link aura (__popcountdi2, main too), so only the clang image builds count.

  • Rebased branch, locally: make format-check (clang-format 20.1.8) and make rustfmt-check clean; clang builds of Stage 1 and the ESP Stage 2 and both esp-stage2-size configs OK (ESP vital region 745480 B of 1179648 B); pytest tests/python + T8122 tests 832 passed, 27 skipped (gcc), 831 passed, 28 skipped (USE_CLANG=1); the seven CI host tests pass with gcc and clang (kboot audio 28 scenarios, DT-full 116 whole / 13 none), M3 start.S move gate pass under qemu, run-pmp-boot-data.sh OK. The local GCC 16 cannot link aura (missing __popcountdi2, main too), so the gcc image builds were not rerun here.

  • Release build (RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 USE_CLANG=1) of the full stack OK; clang-format clean on every changed file.

  • Host tests: tps6598x command tests (4 new), kboot audio scenarios (new DT-full sweep), nvme adoption, kboot extraction tests pass; the eight tests/run-*.sh host tests now wired into CI pass locally with gcc and clang.

  • M2 (T8112) aura-try, ESP Stage 2 1.0.0b13-g976da6f1: PASS. Enforcing, 0 failed units, 0 AVC, 0 kernel errors; NVMe, Wi-Fi, AVE h264/h265 encode md5 identical to production; s2idle 3/3; amp configuration for 4 amps; U-Boot leaves the watchdog to the trial budget. Same rows again with the U-Boot from apple: bound power-state changes in their real unit, name the T8140 eUSB2 settle u-boot#64. Production restored, Stage 2 hash unchanged.

  • Neo (T8140 J700) aura-try, same Stage 2: PASS. Enforcing, 0 failed units/AVC/kernel errors; NVMe, 31 USB devices, Wi-Fi; s2idle 3/3. This boot adopts the live ANS session, so the ANS power-off and rtkit_stop paths did not run here (no-regression only). Same rows with the U-Boot from apple: bound power-state changes in their real unit, name the T8140 eUSB2 settle u-boot#64.

  • M1 Pro (T6000) aura-try, same Stage 2: PASS. Enforcing, 0 failed units/AVC/kernel errors; NVMe, Wi-Fi; s2idle 3/3; amp configuration for 6 amps and speaker ID as on production. Same rows with the U-Boot from apple: bound power-state changes in their real unit, name the T8140 eUSB2 settle u-boot#64.

  • J616s (T6040) aura-try, same Stage 2: PASS. Enforcing, 0 failed units/AVC/kernel errors; AOP firmware segments reserved (success path of the new AOP check), AOP driver bound and ready; NVMe, 8 USB devices, eDP, Wi-Fi; s2idle 3/3; amp configuration for 6 amps and speaker ID as on production. Same rows with the U-Boot from apple: bound power-state changes in their real unit, name the T8140 eUSB2 settle u-boot#64.

  • CI green (16/16), including the newly wired host tests (kboot audio 28 scenarios with the DT-full sweep, T6030 display, start.S move gate under qemu). Locally: full pytest 783 passed, 27 skipped.

Still to run

  • Boot rows at this head f224aa4 over main's generalised dt_set_aop_firmware(): the four lab rows below ran on the pre-rebase Stage 2. M2 (T8112) and J616s (T6040) first, for the AOP path.
  • Neo (J700) CDC transition row across cold and warm boots and both cable orientations: application firmware ready N ms after reset with N > 0.
  • Note: the ANS power-off and rtkit_stop paths do not run on a normal boot of these four Macs (ANS is adopted or sleeps normally), so those rows show no regression rather than exercise.
  • Community rows for J813 (N1 PCIe), J775D (T6050 PCIe) and J873/J873g (USB2, USB-C display, HDMI), which no lab Mac covers.
rtkit: wait for the coprocessor's stop bit, not a fixed 1 ms

Problem

rtkit_stop() clears RUN on a coprocessor that never acknowledged a power transition, then waits a fixed 1 ms before draining the mailbox. The ASC reports when its CPU has halted (CPU_STATUS.STOPPED), so the fixed wait is either too long or, if the CPU has not halted, silently too short.

Change

Poll CPU_STATUS.STOPPED (new asc_cpu_stopped()) with the same 1 ms bound, now RTKIT_STOP_TIMEOUT_US. If the CPU has not halted by then, print the status word. The caller's reset follows either way, as before.

Testing

  • Release build (RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 USE_CLANG=1) OK; clang-format clean.
  • tests/python/test_nvme_adoption.py passes.

Still to run

  • aura-try ESP Stage 2 rows on M1 Pro and M2 (the ANS sleep-timeout shutdown path) and Neo (T8140 cold handoff): warm reboot loop, U-Boot finds NVMe, "CPU not halted" never printed.
Where this runs

Only the rare ANS sleep-timeout paths in nvme.c (M1-M3 shutdown after a sleep timeout, T8140 cold handoff). The worst case is still 1 ms. Status bit layout used: RUNNING bit 0, STOPPED bit 1, IDLE bit 5 (aura already reads bit 1 for an idle DCP).

kboot: refuse a trial payload whose watchdog U-Boot would take over

Problem

On an aura-try trial, kboot marks the watchdog node u-boot,noautostart so U-Boot leaves the trial watchdog alone. If that property could not be set, kboot logged it and handed off anyway: U-Boot would take the watchdog over and feed it, and a trial that hangs in U-Boot would never reset back to the configured Stage 2.

Change

dt_set_trial_watchdog() returns an error when the property cannot be set, and kboot_prepare_dt() refuses the payload. The trial path then reboots into the configured Stage 2, as for any trial that cannot start its payload. Non-trial boots are unchanged.

Testing

  • Release build OK; clang-format clean; the kboot extraction tests pass.

Still to run

  • One aura-try trial on a lab Mac: the log still shows "U-Boot leaves the watchdog to the trial budget" and the trial boots.
Scope

Every chip, trial boots only, and only when the FDT write fails (e.g. no space left in the DT buffer).

kboot: disable the T6040/T6041 AOP when its firmware segments are not reserved

Problem

On T6040 and T6041 the OS starts the AOP from the DRAM segments the boot loader left, mapped through the AOP's DART from the reservations kboot adds. When that reservation failed, kboot logged it and left the AOP enabled: those pages were then free RAM to the OS, and the AOP would be started on code in pages the kernel reuses.

Change

Disable the AOP node instead, as the T8132 AOP handoff already does for the same failure, and refuse the handoff only if the node cannot be disabled. A successful reservation is unchanged.

Testing

  • Release build OK; clang-format clean.

Still to run

  • aura-try on the J616s: expect "AOP firmware segments reserved" and the AOP probing in Linux as today.
Scope

T6040 (J614s, J616s, J773s) and T6041 (J614c, J616c, J575c), only on reservation failure. Segments in the AOP's own SRAM are skipped on purpose and are not a failure.

sptm_virt: call AURA_TRAP_DELAY_NS a diagnostic

Problem

AURA_TRAP_DELAY_NS in sptm_virt_gl.c is described as "a workaround knob, not a fix". It is off by default, but nothing says what it is for or what it found, so it reads like a hidden fix.

Change

Comment and tool help text only: call it a diagnostic, record what the trap-delay bisection showed (only sysreg traps move the guest stall; the stall follows ISP power-up; hiding isp + dart-isp removes it), and point at the tracking issue (#342). The environment variable name is kept because existing run scripts use it. No behaviour change.

Testing

  • Release build OK; aura.bin unchanged in behaviour (default 0 delay).

Still to run

  • Nothing on hardware (comment-only). The knob is removed together with the real fix for the stall.
tps6598x: wait for the HPM firmware after a reset instead of fixed sleeps

Problem

On J700 the CDC transition resets HPM0 with Gaid and then sleeps a fixed 1000 ms. Gaid never completes like other commands: the controller resets (clearing CMD1) and boots its firmware. The fixed sleep is too long when the firmware is back quickly, and the code carries on even when it is not back. The debugusb path does the same with a fixed 20 ms.

Change

  • Add tps6598x_wait_ready() (with a host-testable core tps6598x_reset_wait_execute()): wait until CMD1 no longer reads Gaid (or the transport drops), then until MODE reads APP or APP1. On SPMI, wake the controller again after a transport error.
  • Bound: TPS6598X_RESET_READY_MS = 2000 (TI's reset-to-ready is 1000 ms, Linux TPS_SETUP_MS; Linux allows 2000 ms for its reset command). On timeout, log MODE and the elapsed time and fail the transition.
  • Use it after the CDC cold reset (replaces mdelay(1000)) and after the debugusb reset (replaces mdelay(20)).
  • MODE values and the !CMD reply become four-character tags.

Testing

  • 4 new host tests in tests/python/test_tps6598x_command.py; the existing tps/HPM/CDC tests pass (39 total). test_cdc_reconnect.py needs pyserial, not run.
  • Release build OK; clang-format clean.

Still to run

  • J700 CDC transition, cold and warm boot, both cable orientations, 3+ runs: record tps6598x: application firmware ready N ms after reset, Gen1 enumeration and the CDC ATC: lane= line.
  • Debug boot after a forced CMD1 error on one I2C Mac (M1/M2) and one SPMI Mac (M3+).
Detail

HPM0 is /arm-io/nub-spmi-a0/hpm0 (usbc,sn201202x,spmi). The wait runs in the same session as the Gaid write; SPMI register selection uses the 2 s budget so a stuck select cannot run past it. After success the session ends with the normal SPMI shutdown. The CDC path only runs on T8140 (J700) from the proxy window; the debugusb path runs on every SoC in debug/USE_DEBUG_USB builds, and only when the status check before LOCK fails.

usb: name the CDC schedule flags and the ATC USB2 PHY/PIPE fields

Problem

The CDC schedule flags, the recovery budget and the ATC USB2 PHY / PIPE register writes in the CDC paths were bare numbers.

Change

Name them: schedule flags and recovery budget in usb_cdc_state.h, and the ATC USB2 PHY and PIPE fields in a new src/usb_atc_regs.h (names as in Linux drivers/phy/apple/atc.c), used by the T6050, T8140 and T8152 paths. Values with no public name (lane mode, crossbar, PSD/AON/GATE power registers) stay raw. No functional change.

Testing

  • usb.o, usb_t8152.o and usb_cdc_atc.o disassemble identically before and after.
  • Release build OK; clang-format clean.

Still to run

  • Nothing on hardware (no code change).
pcie: poll endpoint config readiness, PERST#/refclk timing from the ADT

Problem

The J813 N1 and T6050 endpoint bring-ups slept bare 100 ms intervals and judged the endpoint by one config read. j813_n1.c also carried its own copy of the SMC function-reset release with the key hard-coded, a hard-coded PERST# pad and a fixed refclk time, all of which the ADT provides. Some comments named macOS driver internals.

Change

  • Release the N1 through smc_adt_function_reset() on pci-bridge0 (the 50 ms hold is named N1_RESET_SETTLE_MS, as on T6050).
  • Name the spec waits: PCIe CEM T_PVPERL (PCIE_CEM_T_PVPERL_MS) and PCIe Base 6.6.1 (taken from the bridge's ADT perst-to-config, spec value as the floor).
  • Replace the one-shot ID read with pcie_wait_config_ready(): polls past all-ones and Request Retry Status for up to 1.0 s (PCIE_RESET_READY_MS) and fails loudly.
  • Read PERST# and the refclk time from the ADT (function-perst, t-refclk-to-perst) through a shared pcie_adt_perst_gpio() moved from pcie_t6050.c into pcie.c.
  • Describe the steps in comments instead of naming macOS drivers.

Testing

  • Release build OK; clang-format clean.
  • ADT check (our own ADT dumps): the PERST# pad resolves to the old hard-coded address on J813; perst-to-config and t-refclk-to-perst are 100 on every apcie bridge in the J813, J873, J873s, J700 and J773s ADTs.

Still to run

  • J813 cold boot: j813-n1: link up ... endpoint 106b: and Wi-Fi in Linux.
  • J775D cold boot: port N up for ports 2, 3 and 0, plus one boot that adopts an already-up link.
  • Community rows requested for both (no lab J813/T6050).
What can change

On a healthy endpoint the register writes and delays are unchanged. New: if the J813 ADT lacks function-reset, function-perst or t-refclk-to-perst, N1 bring-up stops and the ECAM host is disabled (fail closed). A slow endpoint now gets up to 1 s to answer config space instead of being judged by one read. Remaining fixed waits without a known status bit are tracked in #344.

pcie: stop the ANS power-off if a PHY clock does not drop

Problem

The whole-block ANS power-off (post-M4 chips) cleared each PHY's clock requests and polled for the acks to drop, but ignored the poll results: if a clock never dropped, the ANS gates were cut anyway.

Change

Check both polls. On timeout, log the PHY control word and return -1 before any gate is touched; the caller reports "couldn't power ANS off".

Testing

  • Release build OK; clang-format clean.

Still to run

  • ANS power-cycle / chainload rows on the Neo (T8140) and J616s (T6040): pcie: Timeout dropping PHY never appears, NVMe comes up in U-Boot and Linux.
Scope

T8132, T8140, T6040, T6041 whole-block ANS power-off. Behaviour only changes when a clock ack does not drop within 50 ms; before, that case cut power with the PHY clock still running.

j873: poll for the eUSB2 PHY's UTMI clock

Problem

j873.c slept 1 ms after enabling the eUSB2 PHY and then checked the UTMI clock once.

Change

Poll the UTMI clock event counter within the same 1 ms bound and fail as before if it never runs; name the three other settle waits (EUSB2_POWER_SETTLE_MS, EUSB2_RESET_SETTLE_US, EUSB2_MODE_SETTLE_MS, tracked in #344).

Testing

  • Release build OK; clang-format clean.

Still to run

  • J873 (T8152) cold boot: both USB2 hosts reach host mode and enumerate a device. Community row requested.
kboot: whole speaker amp group configuration or none

Problem

kboot hands each speaker amp group's configuration (brownout prevention, DC blocker, per-amp speaker and sense slot rows) from the ADT to every amp of the group, and the file promises that the kernel gets either the whole group's configuration or none of it. A DT write that fails part way (no room left in the tree) broke that: the amps written before the failure kept the new properties and the rest did not, so the amps of one speaker group were set up differently.

Change

On a failed write, remove every one of these properties from all of the group's amps again (removing a property never needs room in the tree) and log it. A group written in full is unchanged; nothing here stops the boot, as before.

Testing

  • tests/run-kboot-audio.sh gains a sweep over the free space left in the tree (0..2048 bytes, step 16). Old code: 0 bytes free leaves a partial group (test fails). New code: each of 129 sizes gives the whole group (116) or none of it (13); all 28 scenarios pass.
  • Release build OK; clang-format clean.

Still to run

  • No behaviour change on a normal boot (the tree has room). aura-try rows on M1 Pro / M2 / J616s / Neo check kboot: audio: ... amp configuration for N amps is unchanged.
T8152 display: fail closed on calibration, name the waits

Problem

The T8152 HDMI PHY activation kept going after an impedance-calibration timeout and then programmed the termination from a register that holds no result until calibration completes. A missing PHY node silently skipped every tunable. The T8152 ATC and dptx-phy bring-up used bare delay literals (one duplicated), the DPTX port service 22 unnamed IOReturn literals, and some comments named another driver's internals.

Change

Still to run

  • J873g cold boot: USB-C (ATC3) display and HDMI second display modeset unchanged.
Host tests in CI

Nine tests/run-*.sh host tests were never run by CI; one (T6030 display) had stopped linking because kboot_atc.c gained libfdt address-cell and ADT compatible calls. Fixed the test, and run eight of them on the ubuntu-latest jobs (dtc + qemu-user installed; the start.S move gate on the LLVM job). run-smbios.sh needs a Mac's ADT/DTB and stays out.

Tracking issues for the waits that still lack a status bit: #342, #343, #344, #372.

Assisted-by: LLM (Claude:Opus 5.5)

RyanTheTide and others added 29 commits November 22, 2026 08:18
…ed 1 ms

rtkit_stop() clears RUN on an IOP that never acknowledged a power
transition, waited a fixed millisecond for messages still in flight,
and drained the mailbox. The ASC reports when its CPU has halted in
CPU_STATUS.STOPPED (bit 1, the bit aura already reads for an idle
DCP), and nothing the CPU sends can follow that.

Poll that bit instead, with the same 1 ms bound named
RTKIT_STOP_TIMEOUT_US, and say so with the status word when the CPU
does not halt in time. The caller's reset follows either way, as
before.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
On an aura-try trial every aura stage arms the trial watchdog, and
kboot marks the watchdog node u-boot,noautostart so that U-Boot leaves
it alone; a U-Boot that waits forever then still resets into the
configured Stage 2. When that property could not be set, kboot logged
it and handed off anyway: U-Boot would take the watchdog over and feed
it, and a trial that hangs in U-Boot would never be reset, with nobody
at the Mac.

Fail closed instead: kboot_prepare_dt() refuses the payload, and the
trial path reboots into the configured Stage 2 as for any trial that
cannot start its payload. Non-trial boots are unchanged.

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

On T6040 and T6041 the OS starts the AOP from the DRAM segments iBoot
left (__ETEXT and __OS_LOG), mapped through the AOP's DART from the
asc-mem reservations kboot adds. When that reservation failed, kboot
logged it and left the AOP enabled: those pages, or the ones after a
partial failure, were free RAM to the OS, and the AOP would be started
on code in pages the kernel reuses.

Disable the AOP node instead, as the T8132 AOP handoff already does for
the same failure, and refuse the handoff only if the node cannot be
disabled. A successful reservation is unchanged.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The trap delay was described as a workaround knob. It is a default-off
bisection aid: sptm_virt_trap_delay_ns is 0 and only run_guest_sptm.py
writes it. Say so, and record what the bisection found since: only the
sysreg traps matter (t106-t110), SPTM's rare EL2 control writes alone
do not (t115), and the last guest writes before every stall power up
the camera ISP; with the ISP and its DART hidden the guest runs on
without a delay (t121, eb66562). The race itself stays open and is
tracked in its own issue.

No code change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The J700 CDC transition reset HPM0 with Gaid and then slept a fixed
second before talking to it again. Gaid never completes like other
commands: the controller resets, which clears CMD1, and then boots its
application firmware, which reports itself in the MODE register.

Wait on that instead. tps6598x_wait_ready() first sees CMD1 lose Gaid
(or the transport drop while the controller is in reset), so the old
firmware's MODE cannot pass as ready, then polls MODE until it reads
APP or APP1. Transport errors during the reset are expected; on SPMI
the controller is woken again before the next poll. The wait is
bounded by TPS6598X_RESET_READY_MS (2000 ms: TI's 1000 ms reset to
ready, Linux tipd TPS_SETUP_MS, inside the 2000 ms Linux allows the
reset command) and fails the transition, loudly, when the firmware does
not come back, instead of carrying on into a controller that is not
there.

Name the MODE values and the !CMD reply as four-character tags.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
When the port controller reports a failed command before the DebugUSB
LOCK, it is reset with Gaid and given 20 ms before LOCK. Gaid reboots
the controller's firmware, which TI allows up to 1000 ms; polling CMD1
for the reset to complete also fails as soon as the transport drops
during the reset.

Write Gaid without waiting for a reply and wait for the application
firmware with tps6598x_wait_ready(), as the CDC transition does, before
LOCK. The DebugUSB setup now fails, with the controller's MODE in the
log, when the firmware does not come back within
TPS6598X_RESET_READY_MS.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The CDC schedule flags were bare bits (BIT(0) lane swap, BIT(1) Gen1,
BIT(2) HPM cold reset) checked as 7u/2u masks, and the schedule window
and re-advertise budget were literals repeated in three places. Give
them names in usb_cdc_state.h and use them in usb_cdc.c, the state
machine and the Stage 1 proxy window. No change in behaviour.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T8140 CDC ATC path kept its own copy of the USB2 PHY and PIPE
handler offsets and wrote their bits as bare numbers, and the T8152 USB0
path used raw offsets for the USB2 PHY, the PIPE handler and the DWC3
core (0xc200, 0xc2c0, 0xc120, 0xc704). The T6050 path compared the PIPE
mux against 0x73/0x42/0x22.

Move the USB2 PHY, PIPE handler and USB2 event counter registers out of
usb.c into usb_atc_regs.h, named and laid out as in Linux
drivers/phy/apple/atc.c, add the per-generation MUX_CTRL field helpers,
and use them, and the existing DWC3 register names, in all three paths.
The PSD/AON power registers of the T8152 path have no public names and
stay as they are.

No functional change: usb.o, usb_t8152.o and usb_cdc_atc.o disassemble
identically before and after.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
j813_n1_reset() was a copy of smc_adt_function_reset() with the SMC key
and value of pci-bridge0's function-reset (pKW4 'gP13', 0x800000)
hard-coded. Use the helper on the bridge's ADT node instead, as the
T6050 and J873 N1 paths already do: same writes (level 0, then 1, 50 ms
each), but taken from the ADT, and a missing or non-SMC function-reset
now stops the bring-up instead of writing a key the board may not have.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The J813 N1 and T6050 GP bring-ups slept a bare 100 ms after the SMC
function-reset release and again after link-up, then read the
endpoint's ID once. Both waits are spec times, and the single read is
where a readiness poll belongs:

- After the function-reset release: PCIe CEM T_PVPERL, at least
  100 ms with the endpoint powered before PERST# is deasserted
  (PCIE_CEM_T_PVPERL_MS).
- After link-up: PCIe Base 6.6.1, at least 100 ms after link training
  before the first Configuration Request on a port faster than
  5 GT/s. Every apcie bridge in the ADT states this as perst-to-config
  (100 on J813, J873, J873s, J700, J773s); pcie_adt_perst_to_config_ms()
  takes the longer of it and the spec value.
- Then the endpoint has until 1.0 s after reset to complete config
  requests (Base 6.6.1). pcie_wait_config_ready() polls its vendor ID
  past all-ones and Request Retry Status for up to that long, and fails
  loudly if it never answers, instead of judging the endpoint by one
  early read.

No change to the time either path spends on a healthy endpoint.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
j813_n1.c drove PERST# through a hard-coded pad address (0x39a000300,
AP GPIO 192) and waited a fixed 1 ms for refclk-to-PERST#. pci-bridge0
gives both: function-perst = GPIO(0xc0) of /arm-io/gpio0 and
t-refclk-to-perst = 100 (us). pcie_t6050.c already resolved its pads
that way, inline.

Move that resolver to pcie.c as pcie_adt_perst_gpio() and use it from
both, and resolve J813's pad and refclk time before anything is
powered, so a board whose ADT lacks them stops cleanly. The 1 ms floor
both paths keep over the ADT's 100 us is named
APCIE_REFCLK_TO_PERST_MIN_US: it is what every bring-up has used, and
nothing shorter has been tried.

The J813 pad resolves to the same address (gpio0 0x18a000000 + arm-io
0x210000000 + 4 * 0xc0); no change in what is written.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
0bbd6f3 reworded two of j813_n1.c's comments; the file header and
five step comments still named macOS driver classes and methods, and
the T8142 ANS gate comment in pcie.c named the macOS driver. Say what
each step does instead. No code changes.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
pcie_ans_power_off()'s whole-block path (post-M4 SoCs without a storage
gate table: T8132, T8140, T6040, T6041) drops each PHY's CLK1 and CLK0
requests and polls for the acknowledges to fall, but ignored the poll
result and powered the gates off regardless, the same way whether the
PHY let go of its clocks or not.

Check both polls. On a timeout, log the PHY control value and return
-1 before any gate is touched; nvme already treats a failed ANS
power-off as fatal for this boot ("stays down until a reboot") rather
than continuing on a half-stopped PHY.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
j873_usb_phy_host() slept 1 ms and then read the UTMI clock event
counter once to decide whether the PHY started. The counter is the
readiness signal: poll it for up to that same 1 ms and go on as soon
as it moves, failing as before if it never does.

The three remaining waits (10 ms power-up settle, 1 ms after the PHY
reset release, 5 ms before the mode switch) have no status bit we
know of; name them, with a pointer to the tracking issue, instead of
leaving bare numbers.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…fails part way

kboot_audio hands each SN012776 amp group's configuration (brownout
prevention, DC blocker, per-amp speaker and sense slot rows) to every
amp of the group, and documents that the kernel gets either the whole
group's configuration or none of it. That held for a group whose amps
could not be matched, but not for a DT write that failed part way (no
room left in the tree): the amps written before the failure kept the
new properties, the rest did not, and the amps of one speaker group
were set up differently.

On a failed write, remove every one of these properties from all of the
group's amps again (removing a property never needs room in the tree)
and say so. A group that is written in full is unchanged.

The host test gains a sweep over the free space left in the tree: with
the old code 0 bytes free leaves a partial group; now each of 129 sizes
gives either the whole group (116) or none of it (13).

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
kboot_atc.c now reads #address-cells/#size-cells through libfdt's
fdt_address_cells()/fdt_size_cells() and matches ADT compatibles with
adt_is_compatible(). The host test linked neither, so it no longer
built; nothing noticed because no CI job runs it.

Link libfdt's fdt_addresses.c and add an adt_is_compatible() stand-in
that matches any entry of the compatible list, as aura's ADT reader
does. All checks pass again with gcc and clang.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Eight tests/run-*.sh host tests (speaker amp configuration and
speaker ID, logo, payload profile, T6030 display facts, T8122 PMP,
full start and GPU diagnostics, and the M3 start.S move gate) were
never run by CI, and one of them had stopped building unnoticed.

Run them on the ubuntu-latest jobs, with dtc and qemu-user installed;
the start.S move gate runs on the LLVM job, which has clang and the
LLVM binutils. run-smbios.sh stays out: it needs a Mac's ADT and DTB.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T8152 HDMI phy activation logged an impedance calibration timeout and
then programmed the termination from 0x1c24 anyway, which holds no
calibration result until the completion bit is set. A missing phy node
likewise skipped every tunable and carried on.

Poll the completion bit with poll32() and a named 1 s bound (the old
loop's 100000 x 10 us), and return an error from both cases so
DPTX_APCALL_ACTIVATE reports kIOReturnError instead of training a link
on an uncalibrated phy.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T8152 USB-C (ATC) and HDMI (dptx-phy) bring-up waits between control
steps with bare udelay()/mdelay() literals. None of these steps has a
known status bit; the ones that do (CFG status, crossbar acks, PSD, PLL
ack/lock, impedance calibration) are already polled.

Name each wait and say what it separates: ATC_STEP_DELAY_US for the
clamp/power/isolation/sleep steps, ATC_DPTX_DISABLE_SETTLE_US,
ATC_ALT_MODE_POLL_MS for the alternate-mode poll interval, and
ATC_ROUTE_SETTLE_MS and DPTX_T8152_POWER_SETTLE_MS, whose cause is not
known and which carry tracking references. The lane enable loop waited
twice in a row after the last step; that duplicate is dropped (2 us ->
1 us per lane). No other timing changes.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The DPTX port service replies used 22 bare 0xe00002xx literals, only some
of them commented. Name the four codes after the public IOKit IOReturn.h
values and give apcall 26 an enum entry instead of a bare case label.
No functional change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Some comments in atc_phy.c and dptx_port_ep.c named another
driver's build, its internal tables and function names, and an
attribute field name. Describe what each step does instead. Comment
changes only.

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

test_pcie_sequence.py compiles src/pcie.c without its includes against
host stand-ins. pcie.c now names its reset waits in pcie.h and polls
config readiness with timeout_calculate()/timeout_expired(), so the
harness no longer built.

Take the PCIE_/APCIE_ defines from pcie.h itself (so they cannot drift)
and add max() and poll-counting timeout stand-ins.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
USB_CDC_FLAGS_ALL is too long to align with the flag definitions above
it, and clang-format 20 and 22 disagree about how to lay it out inside
that block. Give it its own comment and paragraph. No code change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The config-readiness timeout message printed a u64 with %lx. On aura
u64 is unsigned long, but the PCIe sequence host test builds pcie.c
with the host's uint64_t, which is unsigned long long on macOS, and
-Werror=format stops it there. Cast the address to unsigned long. No
change on aura.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
qemu-user-static is only a virtual package on the current
ubuntu-latest image, so apt refused it. qemu-user ships the
qemu-aarch64 binary the start.S move gate looks for.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
tps6598x_reset_wait_execute() took any CMD1 value other than Gaid as the
reset having started, including !CMD, the controller's answer to a
command it refused. MODE then still reads APP from the firmware that never
reset, the wait returned 0, and the debugusb path went on to LOCK a
controller that was not reset. The old tps6598x_command() returned -1
there.

Return -1 when CMD1 reads !CMD. The host test answers Gaid with !CMD and
APP in MODE and expects -1 after the single CMD1 read.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
pcie_adt_perst_to_config_ms() raised the ADT bridge's perst-to-config to
the 100 ms minimum but passed any larger value through, straight into
mdelay() on the N1 and T6050 paths. A function completes configuration
requests within 1.0 s of a conventional reset (PCIe Base r6.0 6.6.1,
PCIE_RESET_READY_MS), so a longer value is bad data: use the bound and
say so in the log.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
When reserving the AOP's firmware segments or DAPF windows failed, the
loader grew the node's status to "disabled" and refused the whole boot
if that failed too. The reservation usually fails because the DT is
full, so growing the property is likely to fail the same way.

Overwrite "okay" in place with "fail" (same length, no new space; Linux
treats any status other than "okay" as unavailable), and grow the
property only when there is no "okay" to overwrite. The boot is refused
only if neither works. Both AOP paths (T8132 and the ADT-segment path)
share the helper.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
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.

Blockers: 1 (carried over from #416, still unfixed here).

I range-diffed this PR against #416's last head (50c21b0). 28 of the 29 commits are identical. The only code change is the conflict resolution in the AOP-disable commit (3082dd6, then 7a6ad77). So the earlier fixes carry over: Gaid !CMD fails the reset wait, perst-to-config is capped at 1 s, and the AOP is disabled in place on a full DT. Every wait is still bounded with a safe fallback, and the PR adds no knobs, cmdline params or chip gates.

  1. src/rtkit.c:1072 (unchanged from #416, raised there at 16:52Z): rtkit_stop() still treats CPU_STATUS.STOPPED alone as "halted". asc_cpu_idle() (src/asc.c:182) shows that an IOP waiting in its idle loop reads STOPPED|IDLE while RUN is still set. An idle IOP therefore passes the first read, and the final rtkit_drain() runs at once instead of after the old 1 ms window. That is the late-acknowledgement case this function exists for. Fix: wait for STOPPED with IDLE clear, or keep draining until the 1 ms bound and use STOPPED only to end the log line early. Add a host test with status 0x22 on the first read.

  2. src/kboot.c:9690-9702: the rebase changed the scope of the AOP fallback. On current main, dt_set_aop_firmware() has no T6040/T6041 gate any more. Every non-T8132 AOP whose ADT has segment-ranges and whose DART is not locked reaches this reservation, which includes T8112 since #377. The commit subject, the body ("T6040/T6041 ... only on reservation failure") and the "iBoot leaves it stopped" argument from the #416 review were all written for the old scope. Disabling the node is only a safe fallback when the AOP has not been started. If iBoot already runs the AOP from those DRAM segments, status = "fail" stops Linux from binding it, but the coprocessor keeps using pages the kernel now treats as free. Please do one of these: (a) show that every chip that reaches this point has a halted AOP at handoff, or (b) read the AOP's ASC CPU_STATUS/RUN at this point and refuse the handoff (or stop the AOP) when it is running, keeping the disable for a halted AOP. Then update the subject and scope text to match.

  3. Evidence: the PASS rows in the body were run on Stage 2 1.0.0b13-g976da6f1 (#416 before the rebase). None was run on f224aa4 or with main's AOP rework underneath. CI on f224aa4 is still pending for gcc, nix, fedora, alarm, clang-macos and three pytest jobs.

Nit (still open from #416): dt_disable_aop() sits between the J713/J604 "iBoot leaves the AOP halted" comment block and dt_set_t8132_aop(), so that comment now describes the wrong function.

HW rows (each on f224aa4 merged with main; 0 AVC, 0 failed units, 0 new kernel errors):

  • M2 (T8112): aura-try Stage 2. Pass: the log shows which AOP line ran (AOP firmware segments reserved or preserving firmware mappings in locked DART), and the AOP sensors still work in Linux as on production.
  • J616s (T6040): aura-try. Pass: AOP firmware segments reserved, AOP bound, s2idle 3/3.
  • Neo (J700): the CDC transition with the HPM reset, cold and warm boot, both cable orientations, 3 runs each. Pass: tps6598x: application firmware ready N ms after reset with N well under 2000, Gen1 enumeration, and not ready never appears.
  • J813/J815, J775D and J873g community rows for the N1 PCIe, T6050 PCIe and T8152 hunks, as listed on #416.

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.

Adversarial review of head f224aa4197ccbfc40e2448fa4216bccd0a01a1c1 against pre-pr-checklist.md.

What checks out

  • Bounded waits & fail-closed hardening: tps6598x_reset_wait_execute() (TPS6598X_RESET_READY_MS = 2000 ms, !CMD rejection, SPMI wakeup and shared deadline budget), pcie_wait_config_ready() (1000 ms bound polling past 0xffff/0x0001), pcie_adt_perst_to_config_ms() (clamped [100, 1000] ms), pcie_init_controller() ans_off CLK1ACK/CLK0ACK poll checks (50 ms each, returning -1 before cutting gates), j873_usb_phy_host() UTMI counter poll (1000 us), dptx_t8152_impedance_calibration() / dptx_t8152_apply_tunables() fail-closed returns, dt_set_trial_watchdog() failing closed on trial boots only, and kboot_audio.c amp_group_clear() rollback on partial DT write failure (swept 0..2048 B spare) are all bounded and structurally sound.
  • No model gating / no new cmdline knobs (§1, §2): No new board/SoC/fw-version gates or boot parameters; J813 PERST#/refclk/SMC reset moved from hard-coded constants to ADT properties.
  • Attribution, CI & size budgets (§4): All 29 commits have clean human authorship and Signed-off-by with no AI trailers; PR body ends with Assisted-by:. 15/15 CI checks pass on f224aa41, including the 8 newly wired host tests; Stage 1 headroom remains healthy (16440 B standard / 16184 B dev-audit / 82096 B secure on fedora & nix; ESP Stage 2 vital region 745,480 / 1,179,648 B).

Blockers

  1. Race bug in rtkit_stop() (src/rtkit.c:1066, src/asc.c:162-165):

    • asc_cpu_stopped() only tests ASC_CPU_STATUS_STOPPED (bit 1). As asc_cpu_idle() (src/asc.c:182-186) and asc_inherited_cpu_state() (src/asc.c:209-216) demonstrate, an IOP sitting in its idle loop with RUN set reads ASC_CPU_STATUS_STOPPED | ASC_CPU_STATUS_IDLE (0x22).
    • When rtkit_stop() clears RUN on an IOP in that state, the very first asc_cpu_stopped() read returns true immediately, collapsing the old 1 ms drain window to ~0 us and running rtkit_drain() before any in-flight late acknowledgement arrives — breaking the exact race rtkit_stop() is meant to close.
    • Fix: require STOPPED with IDLE clear (or confirm hardware halt semantics and continue draining through RTKIT_STOP_TIMEOUT_US when IDLE is set), and add a host test with CPU_STATUS = 0x22 on the first read.
  2. Cross-SoC safety regression in dt_set_aop_firmware() (src/kboot.c:9698-9703):

    • After rebasing onto main, dt_set_aop_firmware() is no longer T6040/T6041-only — it runs for every non-T8132 SoC whose /arm-io/aop carries segment-ranges and an unlocked DART (including T8112/M2 on 27.2, per the function's own comment at src/kboot.c:9650: "iBoot starts the AOP firmware and leaves the part that does not run from the AOP's own SRAM in DRAM").
    • Disabling the DT node via dt_disable_aop(path) (status = "fail"/"disabled") is only safe if iBoot left the AOP halted (as dt_set_t8132_aop() explicitly checks via asc_cpu_running()). If iBoot already started the AOP from those DRAM segments and dt_reserve_asc_segments() fails, marking the DT node disabled stops Linux from binding the driver while leaving a live AOP executing from unreserved RAM that Linux will hand out as free memory.
    • Fix: check asc_cpu_running() on /arm-io/aop before falling back to dt_disable_aop() (refusing the handoff or stopping the AOP if it is running), or prove every chip reaching this path has a halted AOP at handoff; also update commit 3082dd65 and the PR body to reflect the generalized post-rebase scope.
  3. Hardware evidence is stale (pre-rebase) and misses new exercised paths (§5):

    • All four lab boot rows (M2, Neo, M1 Pro, J616s) were run on pre-rebase Stage 2 1.0.0b13-g976da6f1 (#416), not on f224aa41 over main's generalized dt_set_aop_firmware().
    • Re-run aura-try rows on f224aa41 (especially M2/T8112 and J616s/T6040 for the AOP path), plus a J700 (Neo) CDC transition row exercising tps6598x_wait_ready() across cold/warm boots and cable orientations (verifying application firmware ready N ms after reset with N > 0 so CMD1 == 0 doesn't falsely trigger before reset). Community rows for J813 (N1), J775D (T6050 PCIe), and J873/J873g (eUSB2, T8152 display) remain owed.

Non-blocking nits

  • src/kboot.c:9496-9523: dt_disable_aop() was inserted between the J713/J604 comment block and dt_set_t8132_aop(), detaching the comment from its function.
  • src/pcie.c:1080: use base + 4ULL * perst.pin to match the u64 bounds check on line 1076.
  • src/j813_n1.c:167: refclk_to_perst_us read from ADT has no upper bound cap (unlike perst-to-config).
  • src/tps6598x_command_core.c:1509-1515: note the assumption that the controller never clears CMD1 to 0 ahead of actually entering reset while MODE still reads the old firmware's APP ; the J700/M1/M2/M3 reset rows should confirm elapsed > 0.

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

github-actions Bot and others added 3 commits November 22, 2026 11:37
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.
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>
…TS.md

Aurora agent policy: remove assistant instruction files that are not
policy copies, and sync AGENTS.md, CLAUDE.md, GEMINI.md and
.github/copilot-instructions.md to .github/aurora/AGENTS.md on main.

@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 1305d898c47c332d246039c8c555e9a27683c315 against the pre-PR checklist (§1–§6).

Diff since prior review (f224aa4197cc..1305d898c47c)

  • No code or test changes — the three new commits (a0e2a1a663c4 gfya, 595c59a02fee restore, 1305d898c47c agent-policy: sync...) only churn .github/copilot-instructions.md, AGENTS.md, CLAUDE.md, and GEMINI.md (+47/-0 net unrelated diff in the PR).

Blockers

  1. rtkit_stop() race still unfixed (src/rtkit.c, src/asc.c): asc_cpu_stopped() still tests ASC_CPU_STATUS_STOPPED alone, which is also set alongside IDLE (0x22) while RUN is set, collapsing the 1 ms drain window to ~0 us. Require STOPPED with IDLE clear (or continue draining through RTKIT_STOP_TIMEOUT_US when IDLE is set) and add a host test with CPU_STATUS = 0x22 on the first read.
  2. Cross-SoC safety regression in dt_set_aop_firmware() still unfixed (src/kboot.c): After rebasing onto main, dt_set_aop_firmware() runs for every non-T8132 SoC with segment-ranges and an unlocked DART (including T8112/M2). Calling dt_disable_aop() without verifying asc_cpu_running() == false risks leaving an iBoot-started AOP executing from unreserved RAM that Linux hands out as free memory. Check asc_cpu_running() before falling back to dt_disable_aop() (refusing the handoff or stopping the AOP if running) and update commit 3082dd65/PR scope text accordingly.
  3. §4 Commit hygiene (a0e2a1a663c4, 1305d898c47c): Branch history now includes two unsigned github-actions[bot] commits without human Signed-off-by: plus policy-sync churn on the four assistant instruction files. Drop those commits when rebasing onto current main.
  4. CI not running (action_required, 0 check runs): All 6 Actions workflows triggered on 1305d898c47c (build, test, format-check, esp-stage2-size, stage1-size, aurora-agent-policy) ended in completed / action_required without executing any jobs (mergeStateStatus = UNSTABLE). Full CI must run and pass on a clean human-signed head.
  5. §5 Hardware evidence still stale: All four lab rows ran pre-rebase on #416 (1.0.0b13-g976da6f1), not on the rebased head over main's generalized dt_set_aop_firmware(). Re-run aura-try rows on the fixed head (M2/T8112 and J616s/T6040 for the AOP path, plus J700 CDC transition exercising tps6598x_wait_ready() with N > 0; community J813/J775D/J873g rows still owed).

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Replaced by #479 (same code on a clean history, review fixes in 190da50 and 40d0b3a)

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