Skip to content

nvme: apple: start a post-M4 ANS the boot loader powered off - #38

Draft
DjDeveloperr wants to merge 7 commits into
aurora-wipfrom
fix/nvme-apple-t8140-ans-restart
Draft

DjDeveloperr wants to merge 7 commits into
aurora-wipfrom
fix/nvme-apple-t8140-ans-restart

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Draft: the start from off doesn't work yet. Adoption of an older aura's session passed on the Neo in kit-04. The start from off failed in kits 05 to 08; kit-08 showed ANS's CPU still stopped in its idle loop at U-Boot's run bit, so aura's power-off isn't resetting it on this path. See Tested. Don't merge before aurora-silicon/aura#107, and hold the distribution pins until an M4 Mac has booted the pair. Someone with an M4 Max is working with us and may be able to run it.

aura#107 changes how a post-M4 ANS (M4, M4 Pro and Max, and T8140) gets from aura to U-Boot. aura no longer hands U-Boot its running session. It shuts ANS down after its own use, as it already does on M1-M3, and powers ANS's PCIe block off and back on before U-Boot. U-Boot then finds ANS powered with its CPU stopped, plus the SART entries the firmware's buffers need.

The first version of this PR restarted ANS inside U-Boot: a full power cycle of ANS and APCIe with the PHY tables, read from the DT that aura#112 filled. All of that is gone. U-Boot now only writes the SART entries back, sets the run bit and starts the firmware as after a power loss, then sets the controller up as before. It needs no PHY code, no APCIe tables and no power-domain handling.

The DT property

One property on the ANS nvme node, written by aura (aura#107) when ANS will be off at the payload's start:

apple,sart-entries = /bits/ 64 <(index << 8 | flags) address size ...>;

Three 64-bit cells per SART entry. It isn't T8140-specific: apple_nvme_probe() reads it on every post-M4 controller. U-Boot deletes it from the tree it hands the OS, because U-Boot leaves ANS running for Linux. Nothing else goes in the DT for this.

apple_nvme_probe() on a post-M4 controller

What U-Boot finds What it does
apple,sart-entries writes the entries back, sets the run bit and starts the firmware warm (apple_rtkit_boot_warm()), then sets the controller up; on a failure, ANS didn't start from off (<err>); it stays down until a reboot
iBoot's running session, which no stage set up the one-time RTKit handshake, now on every post-M4 controller, not only on T6040
a running session an older aura set up adopts it as before; #40 replaces this with a refusal that names the aura it needs

U-Boot to Linux stays live: Linux still adopts a running ANS. To take the same path at boot, Linux would need three things: read apple,sart-entries at probe and write the entries back, the APCIe and PHY bring-up its wake path already has (t8140-sleep.c), and the warm RTKit start that today only runs on resume.

Commits

  1. arm: apple: sart: write an entry back after a power loss adds sart_set_entry().
  2. arm: apple: rtkit: start an IOP after a power loss under kept firmware state adds apple_rtkit_boot_warm(), the existing boot with a flag: no INIT, the endpoint map answered as macOS does after a wake (bit 1 on every part but the last, the last masked by the caller), no endpoint started again, then AP power on. IOP and AP power reports that come during the handshake are recorded, and other endpoints' messages dropped.
  3. nvme: apple: start a post-M4 ANS the boot loader powered off adds apple_nvme_start_from_off(), the generic handshake check and the fixup that drops the property from the OS's tree.

Compatibility

Stage 1 comes from the installer, which bundles one at build time and replaces an installed Stage 1 when they differ. Stage 2 (on the ESP) and U-Boot come from the distro packages, pinned apart. "Old aura" hands its running ANS session on. "New aura" is aura#107. "#38 + removal" is the held follow-up (#40) that drops the adoption.

For a normal boot (Stage 1, then Stage 2 with U-Boot inline, then Linux):

Stage 1 Stage 2 U-Boot At boot
old old old As today: each stage adopts the running session.
old new old New Stage 2 doesn't touch NVMe and passes Stage 1's session on. Old U-Boot adopts it. Works.
old old or new #38 U-Boot gets Stage 1's running session, no apple,sart-entries, and adopts it as before. Works: kit-04 row legacy passed on the Neo.
old old or new #38 + removal U-Boot refuses with "ANS was handed over running; this U-Boot needs an aura that powers ANS off after use". No NVMe: kit-04 row loud passed on the Neo with this message.
new new #38 or #38 + removal Stage 1 powers ANS off and passes nvme.sart=. Stage 2 brings the PCIe block back and writes apple,sart-entries. U-Boot starts ANS from off. Not yet shown: in kit-05 and kit-06 row chain (Stage 2 in Stage 1's place) aura's half passed and U-Boot's start failed (kits 05 to 07, see Tested); kit-08 reruns it.
new new old ANS is off and old U-Boot can only adopt. No NVMe.
new old any Old Stage 2 ignores nvme.sart=. On T8140 its pcie_init() skips the PHY-IP tables on the powered-off PHY; on T8132 it tries a cold handshake. No NVMe.

boot= (aura loads Linux itself): new aura starts ANS (from off, or off and on from an older stage's session) and leaves it running for Linux, which adopts it as today. U-Boot doesn't take part.

aura#112's tables play no part in booting. Only Linux's deep sleep reads them.

The three "No NVMe" rows are reachable today: an installer with a new Stage 1 on an image with an older U-Boot or Stage 2, or a distro bumping one pin without the other. So none of this ships until the installer and all three distros move together. The distro side is in aurora-silicon/alarm-aurora#174, aurora-silicon/fedora-aurora#213 and aurora-silicon/nixos-aurora#178 (drafts: each package requires the other's version). The installer needs the same gate and has no PR yet.

Pre-M4

Pre-M4 controllers boot ANS through apple_nvme_boot() as before. #23 restarted a pre-M4 ANS and broke the M2 (T8112, apple_rtkit_boot returned -110), and #25 reverted it. Nothing here touches that path: every change is behind post_m4 in the match data.

Measured

The first version passed row 3 of ANS-chain-kit-03 on the Neo (J700) on 2026-11-08: after a full power cycle, the SART wrote back 6 entries, HELLO came 0 ms after the run bit, the endpoint map was 0x51f / 0x3, and ANS was on at 67 ms. U-Boot then read its env and the initramfs (32 MB in 28 ms) and Linux came up with its root on NVMe. That run is where the warm start and SART write-back here come from. It also showed IORVBAR and the I2A mailbox survive the power cycle, so this version doesn't touch them.

This version hasn't run.

Tested

  • At this head, apple_m1 and apple_j873 with WERROR build clean with gcc 16.1.1 (0 warnings) in the build guest, which verified clean before and after. checkpatch has nothing on the series.
  • ANS-chain-kit-04 on the Neo (J700), 2026-11-08, 09973be235 with -DDEBUG on nvme_apple.o and rtkit.o, aura#107 at 7ee13f10 plus aura#112, -77 with its root on NVMe:
    • Row legacy passed: the Neo's installed Stage 1 (an older aura) handed its session on running, and this U-Boot adopted it as before. It read its env and the initramfs from NVMe (32 MB in 27 ms) and handed the session to Linux, which came up with its root on btrfs from NVMe, NVMe live, 64 MiB direct at 1.0 GB/s, and sync.
    • Row chain didn't reach U-Boot. aura's Stage 2 failed its cold PHY bring-up after powering ANS off (pcie: PHY clock enable timed out), fixed in aura#107.
  • ANS-chain-kit-05, row chain, 2026-11-08 11:46 UTC, the same U-Boot image (09973be235): aura powered ANS off, brought its PCIe block back and passed 6 SART entries in apple,sart-entries. U-Boot wrote them back and set the run bit, then read rtkit_boot: unexpected message type 7 (an IOP power-state acknowledgement) where HELLO comes first, and failed with ANS didn't start from off (-22); it stays down until a reboot. Loud, no hang. - ANS-chain-kit-06, 12:06 UTC, with a drain of the mailbox before the run bit (b276b4ee3c) and one in aura after its idle: neither found a message, and U-Boot failed the same way. So the report came from the firmware after the run bit. The warm start, as reworked into rtkit_boot(), took the next management message as HELLO and the one after as the endpoint map, and failed on anything else. This PR's first version (kit-03) waited for HELLO and dropped what came first; Linux handles power reports in any order. This head (a20e374b2d) has the warm handshake record IOP and AP power reports and drop other endpoints' messages wherever they come, each with a debug line, and prints an unexpected message in full. The drain is gone.
  • ANS-chain-kit-07, 12:30 UTC, a20e374b2d with kit-05's aura: aura's half passed a third time. U-Boot logged rtkit: endpoint 0x0 message 0x70000000000020 in the handshake, the IOP reporting its power ON (0x20), and then no HELLO within 1 s: ANS didn't start from off (-110). So after the run bit the firmware went straight to ON, as one that kept running would, instead of restarting. The starts that got HELLO first are macOS after a sleep (it writes the mailbox's I2A control to 0x20001 just before the run bit), this PR's first version in kit-03 (it wrote IORVBAR and enabled I2A before the run bit), and aura's own start, which follows a session with no NVMe shutdown. U-Boot's follows an NVMe sleep shutdown (CC.SHN 3) and wrote neither. This head (66b55b3783) enables I2A receive before the run bit, as macOS does, and logs ANS's CPU and mailbox state just before it. If the firmware still reports power on with no HELLO, it takes that as the kept session picked back up: AP power on, then the controller setup as before, with a debug line saying so. ANS-chain-kit-08, run k08-chain2, 13:05 UTC (the first run lost the chainloaded file on the ESP to an unflushed copy and never reached U-Boot): aura's half passed. U-Boot logged before the run bit: CPU 0x0 status 0x6a, mailbox A2I 0x20001 I2A 0x20001, then the same message 0x70000000000020 (IOP power ON) and ANS didn't start from off (-110). I2A receive was already on, so enabling it changed nothing. CPU status 0x6a has stopped (bit 1) and idle (bit 5) set: ANS's CPU was still stopped in its idle loop after aura's power-off and kboot's power-on, so it kept its state rather than restarting. The resumed-session path didn't run. The likeliest reading is HELLO after the power report, then no endpoint map within 1 s, but the warm path logs no HELLO, so which wait timed out isn't certain. Neither path passed.
  • No M4 Mac has run it.

Size

First version: +1107/-22. Now: +174/-33, in five files.

Base branch

This targets aurora-wip, not main, which is 99 commits behind. #23, its revert #25, and the CTXR window (#32, #36) all landed on aurora-wip, and the distribution packages pin it.

🤖 Generated with Claude Code

A coprocessor's SART loses its entries with the coprocessor's power. An
earlier owner that powered it off can pass the entries on, and
sart_set_entry() writes one back at its index and keeps it, as
sart_init() keeps the entries it finds.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the fix/nvme-apple-t8140-ans-restart branch 2 times, most recently from e9f8a2d to 09973be Compare November 8, 2026 10:25
@DjDeveloperr DjDeveloperr changed the title nvme: apple: T8140: restart an adopted ANS session instead of keeping it nvme: apple: start a post-M4 ANS the boot loader powered off Nov 8, 2026
@DjDeveloperr
DjDeveloperr marked this pull request as draft November 8, 2026 10:43
@DjDeveloperr
DjDeveloperr force-pushed the fix/nvme-apple-t8140-ans-restart branch 2 times, most recently from b276b4e to a20e374 Compare November 8, 2026 12:15
…e state

After a power cycle, firmware that kept its state in DRAM says HELLO by
itself once the run bit is set, and keeps the buffers it was given.
apple_rtkit_boot_warm() is the existing boot with a flag: no INIT, the
endpoint map answered as macOS does after a wake (bit 1 added to every
part but the last, the last masked by the caller), no endpoint started
again, then AP power on. Such firmware can report its power state before
HELLO or between the endpoint map's parts: the handshake records that,
and drops what other endpoints send meanwhile. Firmware that reports its
power on and then says no HELLO picked its kept session back up: AP
power goes on and the session carries on.

Signed-off-by: Diljit Singh <[email protected]>
aura now shuts ANS down after its own use, as on M1-M3, instead of
handing its running session on. It powers ANS's PCIe block off and back
on before U-Boot, so U-Boot finds ANS powered with its CPU stopped, and
the SART entries the firmware's buffers need in the nvme node's
apple,sart-entries: per entry (index << 8 | flags), address and size, 64
bits each.

With that property, apple_nvme_probe() writes the entries back, enables
the mailbox's receive side as macOS does after a sleep, sets the run bit
and starts the firmware as after a power loss, then sets the controller
up as before. Linux still adopts a running ANS, so U-Boot
hands it on running, as before, and drops the property from the OS's
tree.

A post-M4 session straight from iBoot, which no stage has set up, gets
its one-time RTKit handshake on every post-M4 controller, not only on
T6040. A running session from an older aura is adopted as before.

Pre-M4 controllers boot ANS as before.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the fix/nvme-apple-t8140-ans-restart branch from a20e374 to 66b55b3 Compare November 8, 2026 12:36
The warm start took an IOP power report of "on" followed by no HELLO
for a session the firmware had picked back up, and turned AP power on
without a handshake. That came from reading a CPU status of 0x6a as
"kept its idle state". On the J700 the start that failed (ANS-chain-kit-08)
did get HELLO: this branch, built with DEBUG, didn't print, and both
mailbox controls read their reset value. The firmware had restarted,
and what it never sent was the endpoint map after HELLO. The boot
loader stage now disables the controller before it powers ANS off,
which leaves no case for this branch.

Log HELLO and each endpoint map part as debug lines, so a failed start
says how far the handshake got.

Signed-off-by: Diljit Singh <[email protected]>
The warm start answers the last part of the endpoint map with that
part's bitmap masked by last_mask. For ANS that is bit 0, endpoint 0x20,
as macOS answers after a wake. The loop then tested its own reply for
APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE, which is bit 0 too, so it went back
to wait for a part the firmware never sends. The firmware's IOP power
report came in that wait, and the start failed with -110 a second
later.

On the J700 (ANS-chain-kit-09) U-Boot logged HELLO, map base 0, map
base 1 (the last part), then the IOP power report and -110. aura's
three starts from off in the same boot passed: they end the map on the
message's last bit. The "unexpected message type 7" of kits 05 and 06
was the same report, read where the next map part was expected.

End the loop on the reply's LAST bit, which is set exactly when the
firmware's part was the last.

Signed-off-by: Diljit Singh <[email protected]>
@techmore

Copy link
Copy Markdown

An M4 data point for #38 with #40, from one J773g (Mac mini M4, T8132). It's one Mac, but this is the start from off working on an M4.

Build. aurora-wip e1ef8b63, one local J773g commit (keep usb start at boot), this PR at 93f108a0 and #40 at 0ac2fb76 (same patch IDs), plus TEST-ONLY breadcrumbs that are not for merging: CONFIG_FAT_WRITE, a console record with a test-only command that copies it to RAM, a preboot of nvme scan followed by a FAT write of a marker file to the ESP, and a second marker written after the EFI image loads, just before bootefi.

Through the aura proxy, ANS handed over off. Stage 1's proxy chainloaded aura 1.0.0b10. That instance ran nvme_init() and nvme_shutdown(), and kboot_prepare_dt() printed FDT: ANS will be off; 10 SART entries passed on. This U-Boot then started ANS from off and wrote the first marker:

crumb_alive_text=M4 U-Boot alive: NVMe scan and ESP FAT write reached

Linux was booted with booti from RAM on this path.

Native, no proxy. iBoot, Stage 1 1.0.0b8 (installer Alpha 19), an ESP Stage 2 with aura 1.0.0b10 plus the companion aura change below, then this U-Boot. U-Boot wrote both markers and loaded EFI/BOOT/BOOTAA64.EFI (shim) from the ESP. Its console record, saved with the second marker:

Loading Environment from FAT... Unable to read "uboot.env" from nvme0:4...
Model: Apple Mac mini (M4, 2024)
71 bytes written in 12 ms (4.9 KiB/s)
Hit any key to stop autoboot: 0
1045768 bytes read in 1 ms (997.3 MiB/s)
76 bytes written in 11 ms (5.9 KiB/s)

Shim, GRUB and Linux followed. Linux logged efi: EFI v2.11 by Das U-Boot and mounted its root from NVMe. Same result on three boots.

Companion aura change. Stage 1 1.0.0b8 hands ANS on running, with no SART entries. An ESP Stage 2 from aura main that boots its embedded U-Boot never touches NVMe, so it passes that session on as it is, with no apple,sart-entries. That is your "old | new | #38 + removal" row, and natively we got no marker at all. The aura PR "payload: take over a live post-M4 ANS before booting a non-Linux payload" makes Stage 2 take the session over on T8132 and power it off first. With an older Stage 1 on an M4, #38 with #40 needs that change, or a newer Stage 1.

Not covered: U-Boot's own NVMe log lines (no serial console; the record above is what we have), #38 without #40 on an M4, other M4 boards, and M4 Pro and Max.

@techmore

Copy link
Copy Markdown

Three corrections to my comment above:

@niteria

niteria commented Nov 12, 2026

Copy link
Copy Markdown

A T8140 data point, from one MacBook Neo (J700): this PR starts ANS from off in most boots, but 3 of 116 failed, and a trace of one failure shows the firmware sending nothing after the run bit.

Build and chain. aurora-wip e1ef8b63 plus this PR at 93f108a0 (the five commits apply clean), with aura 1.0.0b12 (ea20cedb). The Neo's enrolled Stage 1 is an older aura (1.0.0b9 plus the EL2 sleep return and the APCIe tables, 7b331c58), which hands its session on with nvme.adopt. An aura-try trial loads a raw 1.0.0b12 Stage 1 in Stage 2's place. That Stage 1 powers ANS off, starts it from off itself, powers it off again and chainloads a 1.0.0b12 ESP Stage 2 with this U-Boot inline, which logs FDT: ANS will be off; 6 SART entries passed on. That's the chain arrangement of kits 05 to 08, with Stage 1 starting from an older aura's session instead of iBoot's.

Results, 2026-11-12. Of 116 trial boots, 113 started ANS from off and 3 failed. In one more cycle, either the trial or the regular boot after it failed the same way. aura's own start from off in Stage 1 worked in every boot. A failed boot's panel shows only Failed to probe 'nvme@3cdcc0000': err=-19, twice, and "no bootable entry".

Why the panel shows only err=-19. U-Boot probes NVMe twice while it loads the environment, before console_init_r(): asahi_esp_devpart() from env_fat_get_dev_part(), then env/fat.c's own nvme_scan_namespace(). The first failure's message ("ANS didn't start from off ...") goes to serial only. apple_nvme_adopt_failed then makes the probes from board_late_init() and bootflow return -ENODEV without a message. Keeping the first error and repeating it at those later probes would put it on the panel of a Mac without a serial console.

One traced failure. A test-only record in nvme_apple.c and rtkit.c keeps the first probe's registers and each RTKit receive with timer_get_us(), and prints them on the panel at the first failed probe that shows there. The first probe, with t in µs since boot:

probe t=16423358: sart-entries yes; CPU_CTRL 0x0 STATUS 0x62 BOOT_STATUS 0xde71ce55 CSTS 0x0
before run t=16428980: CPU_CTRL 0x0 STATUS 0x62 A2I 0x20001 I2A 0x20001 BOOT_STATUS 0xde71ce55
  rx warm t=17428985 ret -110

Seconds later, at board_late_init(), ANS read CPU_CTRL 0x10 STATUS 0x60 BOOT_STATUS 0xde71ce55 CSTS 0x0, and the mailbox A2I 0x20001 I2A 0x20001. So nothing came from the firmware after the run bit: no HELLO within the second, and nothing later. The CPU left the stopped state but stayed idle. That differs from kit-08, which got 0x70000000000020 (IOP power ON) first.

STATUS before the run bit was 0x6a in all 7 successful starts captured over Debug USB, the same value as kit-08's. So on this chain 0x6a doesn't mean the start will fail. This failure had 0x62: bit 3 clear (FIQ_NOT_PEND in m1n1's asc.py, marked there as a guess). One failure isn't enough to say whether that predicts the failure.

A timing difference. aura's own start from off (nvme_ans_power_on()) sets the run bit as soon as its pcie_init() returns and the SART entries are back. In the failing boot, Stage 2's pcie_init() finished at 13.09 s and U-Boot set the run bit at 16.43 s, so ANS waited over 3 s with its CPU stopped.

Next. The test build now holds the screen whenever STATUS bit 3 is clear before the run bit, even when the start works. It records the power-state registers of ANS and the APCIe domains. If no message comes, it stops the CPU and sets the run bit again with a new RTKit instance. I'll post what it shows.

Separately, one regular boot of the older chain failed with the same panel, right after a trial's watchdog reset. That chain is 1.0.0b9 Stage 1 and Stage 2 with e1ef8b63, without this PR, adopting the session. About 130 other regular boots of that chain today were fine, about 80 of them with this PR adopting the session. That failure wasn't traced, so its cause is unknown.

… the run bit

On a J700, 3 of 116 starts from off failed: no HELLO after the run bit,
and none later. The traced one read CPU status 0x62 before the run bit;
every working start read 0x6a, the status right after a reset of ANS.
Its CPU had been stopped without a reset since it last ran, and such a
CPU doesn't start again from the run bit.

Reset ANS (its PMGR reset, which takes the SART entries with it) when
the status lacks the reset bit, then write the entries and start it.
When the firmware still doesn't answer, stop the CPU, reset ANS, write
the entries again and start it once more with a new RTKit instance.
Print the status before the run bit and any reset, for a Mac without a
serial console.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@niteria, thanks for the trace: it points at the CPU's state before the run bit, not at the wait.

What 0x62 means.

  • On 2026-11-08 our J700 measured 0x6a as ANS's CPU status right after a real reset: start it once, reset ANS, read the status.
  • Every start that worked read 0x6a before the run bit, as yours did too.
  • Your failure read 0x62: bit 3 clear, with the CPU stopped (bit 1) and idle (bit 5). So its CPU had been stopped without being reset since it last ran.
  • After the run bit it left the stopped state (0x60) but never booted: no message, no HELLO, then or later.
  • Earlier today, handing ANS to macOS cold on our J700, we saw the same thing: a stopped ANS that wasn't freshly reset didn't start again from the run bit. After a reset, the same firmware gave HELLO unprompted.

Why the gap probably doesn't matter in itself.

  • On T8140, aura's pcie_init() turns the APCIe gates and ANS's own gate on with auto-enable cleared. Only the T6050 path sets auto-enable again. So ANS's gate shouldn't auto-idle during those 3 s.
  • What we couldn't settle host-side is why ~3% of the off/on cycles leave the CPU in a non-reset state. Candidates: the gate not reaching off, or something touching the shared APCIe block in between.
  • The change below doesn't depend on which it is.

The change, pushed to this branch as 430b64e8, on top of 93f108a0:

  • Before writing the SART entries: if STATUS lacks bit 3, print it and reset ANS through its PMGR reset (the nvme node's resets = <&ps_ans>, reset_assert_bulk/reset_deassert_bulk). Wait for the reset bit, then write the entries. The reset clears the SART along with the rest of ANS.
  • If the firmware doesn't answer the run bit (HELLO, or BOOT_STATUS OK): clear the run bit, wait for STOPPED, reset ANS, write the SART entries again, enable I2A receive, and set the run bit once more with a new RTKit instance.
  • STATUS before each run bit, and any reset or retry, now go to printf, so a Mac without a serial console shows them.
  • A start that reads 0x6a goes exactly as before.

Testing here. I'll run it on our J700 in two loops of 50 boots, through your chain arrangement:

  • An aura-try marker names a raw b11 Stage 1. It takes the session, powers ANS off and on, reads an ESP Stage 2 with this U-Boot inline, powers ANS off and chainloads it.
  • That Stage 2 then logs "FDT: ANS will be off; N SART entries passed on".
  • Loop A has the change as pushed. Loop B adds a test-only switch that forces the reset path on every boot, so the reset itself is proven 50 times even if a natural 0x62 never turns up.
  • A test-only commit, not pushed here, records each boot's statuses, resets and retries in /chosen.

If you can run 430b64e8 in your loop too, a natural 0x62 that now recovers would be the strongest result.

🤖 Generated with Claude Code

@niteria

niteria commented Nov 12, 2026

Copy link
Copy Markdown

Before trusting the reset path: Aurora's Linux tree stopped using this exact reset on post-M4 ANS because it raised an SError on a J700. aurora-silicon/linux@3053678703b4 ("nvme-apple: Restart a stopped resident ANS without a PMGR reset", carried from Satya's change of 2026-09-18) says:

When a previous boot stage has run the ANS and stopped it cleanly, the driver finds CPU_CONTROL.RUN clear and takes its soft-reset path, which asserts the ANS reset. On post-M4 SoCs that assert raises an SError.

It was tested on T8140 (J700). Since then, Linux restarts a stopped resident post-M4 ANS with the run bit and a fresh handshake, and keeps the reset for older generations.

That's the state 430b64e8 resets from: the CPU stopped and the firmware resident. Its reset_assert_bulk() on resets = <&ps_ans> sets DEV_DISABLE and then RESET in the PS register, as Linux's apple_pmgr_reset_assert() does. Linux's version can also wait for PMGR BUSY (bit 11) to clear between the two (needs_reset_idle_wait, from the J713 work); U-Boot's apple_reset_assert() doesn't.

U-Boot unmasks SError at start (msr daifclr, #0x4 in arch/arm/cpu/armv8/start.S). So if the assert raises one here, do_error() panics and the Mac resets, during the environment's first NVMe probe, before the panel shows anything. I haven't seen this SError myself; it comes from that commit's message.

Your loop B should settle it quickly. We're running 430b64e8 in our loop now, in the chain arrangement from my earlier comment. A working trial boot goes on into Linux, and a test-only record in /chosen shows the status before the start and whether the reset ran. A reset that brings U-Boot down would show up as a quick return to a regular boot. I'll post what it shows.

@niteria

niteria commented Nov 12, 2026

Copy link
Copy Markdown

An update from our loop on the J700. We've paused it for now.

430b64e8. 80 trial starts in our chain arrangement, and every one read 0x6a before the run bit. So its reset path never ran: nothing yet on whether the reset recovers a 0x62 or raises the SError. Also, its new printfs run in the environment's first NVMe probe, before console_init_r(), so they reach serial only, not the panel.

What a working start looks like. Our test build passes U-Boot's record to Linux in /chosen, so every working trial boot left one. Across 117 working starts:

  • before the run bit, STATUS was always 0x6a and BOOT_STATUS always 0;
  • HELLO came 1.92–2.22 ms after the run bit, and the warm start finished 69.3–69.7 ms after it;
  • CSTS.RDY came 3.61–3.78 ms after CC.EN, with exactly three syslog messages from the firmware (endpoint 2, acked) in between;
  • Stage 2 powered the APCIe controller 3.12–3.45 s before U-Boot's run bit.

The traced 0x62 failure also read BOOT_STATUS 0xde71ce55 before the run bit, the value the firmware writes when it boots, where every working start read 0. So more than the CPU was left un-reset: the boot status the firmware wrote in Stage 1's start had survived the power-off. That fits your reading of a stop without a reset.

A second failure, a different one. It came with 93f108a0 plus our trace, before 430b64e8. Before the run bit, STATUS 0x6a and BOOT_STATUS 0, like a working start. HELLO came 2 ms after the run bit, the endpoint map followed, the warm start returned 0 and BOOT_STATUS read 0xde71ce55. Then, after CC.EN, CSTS.RDY never came, and nvme_wait_csts() gave up after CAP.TO (0xf0, so 120 s) with -ETIME. Afterwards ANS read CPU_CTRL 0x10 STATUS 0x6e BOOT_STATUS 0xde71ce55 CSTS 0x0, and the mailbox A2I 0x26601 I2A 0x27701. That trace didn't yet record the messages taken during the wait, so it doesn't show whether the three syslog messages came. 430b64e8 doesn't cover this case, since the start itself worked.

A pattern, not proven. All four failures today came on a trial booted right after a regular boot of the older chain (1.0.0b9 Stage 1 and Stage 2, U-Boot adopting the session, then Linux). After we switched to booting each trial right after the previous trial's Linux, about 100 trials in a row worked. A loop alternating regular and trial boots then gave 19 more working trials before we stopped. At about 3% per boot, that doesn't settle it.

The Neo is back on its daily chain. The loop and the trace build are ready to run again, with 430b64e8 or a later head.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@niteria, loop A from our J700, with 430b64e8 as pushed, in your chain arrangement: 50 of 50 trial boots started ANS from off. 50 boots isn't the hundreds needed for a ~3% failure.

50 boots
STATUS before U-Boot did anything 0x6a every time
reset before the start never (so the new reset/retry path didn't run)
STATUS before the run bit 0x6a every time
attempts 1 every time
run bit → warm start done 67.50–67.59 ms
PMU boot-error/panic count 0 throughout

So, like your 80 starts, natural starts haven't exercised the reset path yet. The timing agrees with your 117 working starts; our measurement points differ slightly. Two things this loop doesn't cover:

  • Your pattern: every trial here followed the previous trial's Linux, and only the first followed a regular boot.
  • The CSTS.RDY failure.

On the SError. Loop B is next on the Neo. It's the same U-Boot with a test-only switch that takes the reset path on every boot, so it answers whether reset_assert_bulk() on ps_ans takes down U-Boot on this hardware. A panic in that first probe would show as a trial that falls back to the regular chain. The loop stops after two of those in a row and records the PMU count.

One related data point. Today aura reset a stopped, resident ANS on this J700 twice, in its macOS cold handoff, with the gate held active: STATUS went 0x6e → 0x6a, and the firmware said HELLO unprompted after. The PS sequence was DEV_DISABLE, RESET, 10 µs, then both cleared. That shows the reset takes effect from that state. It doesn't rule out the SError, since I haven't checked that aura has SErrors unmasked at that point. Loop B does test it.

🤖 Generated with Claude Code

A start from off that is retried frees its RTKit instance first. That
instance's buffers came from LMB through nvme_handoff_shmem_setup(), but
it had no destroy callback, so apple_rtkit_free() passed them to free():
heap corruption once the firmware had asked for any. They also stayed in
the handoff list, published to the OS as reserved memory.

Take them out of the SART, return them to LMB and drop them from the
list instead.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@niteria, loops B and C from our J700, in your chain arrangement. Short version: the PMGR reset raised no SError here, including from a stopped ANS with its firmware resident (20 of 20 boots), and the PR's retry recovered every time. Testing it also turned up a bug in the retry path, now fixed on this branch.

Loop B, 10 boots (430b64e8 + a test switch that takes the pre-reset branch on every boot): 10/10 ok. Every boot reset ANS before the run bit and then started it in one attempt (0x6a before the run bit, 67.52–67.57 ms to the warm start). The switch only masks the status U-Boot reads, though. The hardware was already at 0x6a, so this resets an ANS that is already in reset. It proves the reset's mechanics, not your case.

Loop C, 20 boots: a second test switch makes each boot reach the state your SError question is about.

  1. The first start works (0x6a before the run bit).
  2. U-Boot sends SLEEP, which is acked, clears the run bit and waits for STOPPED.
  3. That leaves the CPU stopped with its firmware resident: STATUS read 0x6e every time.
  4. The PR's own retry path then runs: reset_assert_bulk()/reset_deassert_bulk() on ps_ans, the SART entries written again, the run bit, and a new RTKit instance.

Results:

20 boots
reset of the stopped, resident ANS no SError, no panic (U-Boot went on to Linux every time)
STATUS after the reset, before the second run bit 0x6a every time
second start 20/20 ok; run bit → warm start done 17.31–17.38 ms
PMU boot-error/panic count 0 throughout

So on this J700, at this point in boot, U-Boot's reset of a cleanly stopped, resident ANS doesn't raise the SError described in 3053678703b4. That commit's case may differ in ways I can't see from here: how Linux had stopped it, and the domain state when it asserted. And U-Boot's assert doesn't wait for PMGR BUSY between DEV_DISABLE and RESET, which Linux's can.

Two things this shows about STATUS:

  • A cleanly stopped, resident ANS reads 0x6e, which has bit 3 set. The check in 430b64e8 (reset only when bit 3 is clear) would not reset it. Your failing 0x62 has bits 2 and 3 clear, so it isn't the state a clean stop leaves. The check still matches your failure, and I'm not widening it on one sample.
  • After the reset, the second start reached the warm start in ~17 ms, against ~67.5 ms from off.

The bug, fixed in eec56ee5 (pushed to this branch, which stays draft):

  • apple_nvme_start_from_off() created its RTKit instance with nvme_handoff_shmem_setup but a NULL shmem_destroy.
  • So on a retry, apple_rtkit_free() called free() on buffers that came from lmb_alloc_mem()/map_sysmem(), which corrupts the heap. Those buffers also stayed in ans_handoff_bufs, published to Linux as ans-rtkit@ reserved memory.
  • Your no-HELLO failure never got far enough to allocate buffers, but any failure after the firmware asks for them would hit this.
  • The fix adds nvme_handoff_shmem_destroy(): it removes the SART region, lmb_free()s the buffer and drops it from the list.
  • In loop C every boot frees the first session's buffers, and Linux then saw exactly 3 ans-rtkit@ nodes (16 + 16 + 32 KiB), not 6.

Still open: what leaves a 0x62 (your 4 failures all came right after a regular boot of the older chain), and your CSTS.RDY failure.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

This series is now carried unchanged, rebased onto current aurora-wip, in #48 (all seven commits, authorship kept). This branch conflicts with aurora-wip and has no CI run on its head. Could we continue review and hardware rows on #48 and close this one when #48 merges? The J700 loops (113/116, 50/50, loop B/C) and the J773g rows here stay the evidence for the carried commits. #40 would then need its base moved from fix/nvme-apple-t8140-ans-restart to #48's branch or aurora-wip. Happy to do that retarget if it helps.

@RyanTheTide

Copy link
Copy Markdown
Contributor

I recommend closing this in favour of #48.

#48 carries all seven commits of this branch unchanged, rebased onto current aurora-wip with authorship kept. It merges cleanly, while this branch conflicts with aurora-wip and has no CI run on its head. Review of the retry path (apple_nvme_start_from_off()'s reset-and-retry) and the powered-off handoff has already started there, so please continue on #48 and close this. The J700 loops here (113/116 from off, 50/50 loop A, loops B and C) and the J773g boots stay valid evidence for the carried commits and can be cited from #48. #40, which is based on this branch, needs to move its base to #48's branch or to aurora-wip.

One point to carry to #48, which doesn't seem to have been raised yet: the failing start in the traced J700 boot read BOOT_STATUS 0xde71ce55 before the run bit, and every working start read 0. That register survives the boot loader's power-off, so U-Boot can check it before the first run bit. A non-zero value means the previous session wasn't reset, and that is the state to handle directly, instead of detecting a missing HELLO afterwards and retrying.

HW row: on #48's head. J700, the chain arrangement, at least 300 boots alternating with regular boots (where all four failures came from), with a count of starts that needed the reset. J773g, three native boots. Both with Linux root on NVMe, 0 failed units and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

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.

4 participants