Skip to content

soc: apple: rtkit-helper: start a parked T8140 MTP from its pristine image - #1813

Closed
RyanTheTide wants to merge 1 commit into
djcarry/t8140-mtp-restartfrom
mtp/t8140-park-fresh-start
Closed

RyanTheTide wants to merge 1 commit into
djcarry/t8140-mtp-restartfrom
mtp/t8140-park-fresh-start

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1764.

The T8140 MTP keeps its firmware in SRAM, and a run changes the firmware's data there. #1764 resets the CPU in place before the run bit, but a firmware that already ran then starts with dirty data and never reads INIT (endpoint discovery failed: -62). So a boot loader that used the MTP for its own keyboard has had to hand the running session over (mtp-live-v1).

This lets the boot loader park the MTP instead, and lets Linux start it as a firmware nobody ran.

The contract

The boot loader:

  • saves the whole firmware SRAM before the firmware's first run;
  • at exit, stops the firmware and leaves the CPU held in reset and disabled (RESET + DEV_DISABLE in its always-on PMGR word);
  • passes the saved image as no-map reserved memory:
apple,sram-image = /bits/ 64 <address size>;
apple,sram-image-crc32 = <crc>;

What Linux does with it

Before the run bit, apple_rtkit_helper_restore():

  1. checks that RUN is clear and the CPU is held;
  2. keeps every word of the MTP's power chain fully on with automatic power management off, parents first: fabric, peripheral, SCM fabric, CPU, SRAM, DMA. The SRAM has two parents, the SCM fabric and the CPU, so taking the CPU in and out of reset with only the CPU pinned can take the SRAM path away under the copy;
  3. checks the image's CRC, copies it into the firmware SRAM and reads it back;
  4. takes the CPU out of reset, then enables it.

The firmware then gets the usual INIT, HELLO and endpoint start, with new buffers. Without apple,sram-image nothing changes: the CPU reset in place from #1764, or adoption of a live session.

Device tree

The T8140 mtp node gets the firmware SRAM as reg-names = "firmware" (1 MiB at 0x314c00000) and its power chain as apple,aon-pmgr, apple,aon-power-words (parents first) and apple,aon-cpu-word. pmgr_mini grows to 0x10000 to cover those words. Binding updates will follow once the sequence is proven on hardware.

Tested

  • rtkit-helper.o (W=1) and t8140-j700.dtb build. The only dtc warnings are ones the tree already had. checkpatch --strict: nothing but the trailer form.
  • Not yet run on hardware. Its producer is a U-Boot change that saves the image before the first run and parks the MTP at OS entry. The J700 row comes first, then a T8142 row with that SoC's own power words.

This should be rebased onto #1764's new third commit, which already adds the apple,aon-* properties, their binding and the larger pmgr_mini window.

…image

The T8140 MTP keeps its firmware in SRAM, and a run changes the
firmware's data there. A CPU reset in place starts it from its reset
vector with that data dirty, and it never reads INIT. So a boot loader
that used the MTP had to hand the running session over.

A boot loader can instead park it: save the SRAM image before the
firmware's first run, and at exit stop it and hold its CPU in reset
and disabled. It passes the image's address and size in
apple,sram-image and its CRC-32 in apple,sram-image-crc32.

When those are present, write the image back before the run bit:
check that the CPU is held, keep every word of the MTP's power chain
in the always-on PMGR fully on with automatic power management off
(the SRAM has two parents, the SCM fabric and the CPU), check the
image's CRC, copy it into the firmware SRAM and read it back, then
take the CPU out of reset and enable it. The firmware then starts as
one nobody ran, with INIT, HELLO and its endpoints, and gets new
buffers.

The T8140 tree gets the firmware SRAM as reg "firmware" and its
power chain as apple,aon-pmgr, apple,aon-power-words and
apple,aon-cpu-word; pmgr_mini grows to cover those words. Without
apple,sram-image nothing changes.

Assisted-by: LLM
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 4.

  1. The second start after a restore fails. apple_rtkit_helper_stop() (rtkit-helper.c:428-452) only sends the RTKit sleep and clears RUN. It never puts the CPU word back to RESET|DEV_DISABLE. apple,sram-image stays in the DT, so the next probe (module reload, unbind/bind) goes back into apple_rtkit_helper_restore(). That hits "CPU not held" (:335-340) and returns -EIO, and apple_rtkit_helper_start() (:402-404) then fails the probe: keyboard and trackpad are gone until reboot. Either have stop park the CPU the same way the boot loader does, or restore only once and fall back to the in-place path after that.
  2. The power chain is never handed back. apple_rtkit_helper_ps_pin() (:283-302) clears AUTO_ENABLE and forces every word in apple,aon-power-words to target 0xf, and nothing restores it after the CPU is released, on stop, or on the error returns after :343. That leaves MTP fabric, periph, SCM fabric, CPU, SRAM and DMA pinned on for the whole uptime and through s2idle. Save each word before pinning, and restore the saved values once the firmware has answered HELLO (and on every error path).
  3. This writes PMGR power-state words directly through a syscon regmap, with its own copy of the PS bit layout (:38-47), behind apple,aon-* properties that have no binding. That is the duplication already raised on soc: apple: start and stop the T8140 MTP without a live handoff #1764, now on six words instead of one. If pmgr_mini (t8140-pmgr.dtsi:549, :1293) describes these as pwrstate nodes, the MTP node can take power-domains and resets, and the pin/release becomes pm_runtime plus reset_control_reset() with no new properties. The PR also says it should be rebased onto soc: apple: start and stop the T8140 MTP without a live handoff #1764's later commit, which it conflicts with now.
  4. Commit 25cb89a carries Assisted-by: LLM and Co-Authored-By: Claude ... trailers. Commits should carry only the human Signed-off-by; the Assisted-by line belongs at the end of the PR body.
  5. The readback (:369-375) compares one word per 64 KiB, 16 of the 262144 words. Either compute the CRC over the SRAM after the copy, or compare it in full; it is 1 MiB, once per boot.

There is also no producer yet. Link the U-Boot change, and keep this a draft until it exists and the row below has run.

HW row: J700 with the parking U-Boot, on the head rebased onto #1764. Pass criteria: cold boot gives keyboard and trackpad input with the "image written back" line; modprobe -r/reload of the helper brings input back; the MTP power words read back with auto power management restored after start; 3x s2idle with input after each; a boot without apple,sram-image takes the old path unchanged; 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Closing for now: there is no boot loader that parks the MTP with a saved image yet, and a second start would fail; it can come back with that U-Boot change and a J700 row.

@RyanTheTide RyanTheTide reopened this Nov 22, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Reopened and kept as a draft; the comment above lists what it still needs before review.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Closing for now: there is no boot loader that parks the MTP with a saved image yet, and a second start would fail; it can come back with that U-Boot change and a J700 row.

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.

1 participant