Skip to content

media: apple: ave: run the M2 encoder's macOS 27.2 firmware build - #2904

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
m2mini/ave-t8112-272
Nov 23, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
m2mini/ave-t8112-272

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem

On an M2 Mac booted with the macOS 27.2 (26B123) stub, such as the Mac mini (J473), the encoder never registers. The bootloader preloads a newer AVE firmware build (TEXT 0x11c000, DATA 0x128000), and the T8112 variant only knows the 13.5 build (TEXT 0xd0000), so probe stops with "unexpected firmware segment sizes".

Change

The 27.2 build gets its own T8112 variant, and ave_t8112 points to it through a new next_build link. The 27.2 build starts the way the M3's 27.2 build does: device 12 / type 12 handshake, the 26B123 command layout, lfs_ref_scale 2, a per-boot word at TEXT 0x4224 left out of the CRC, DATA restored before every start. The segment sizes of the firmware reservations the bootloader made pick the build, and the TEXT CRC must then match that build. The 13.5 build's variant and start do not change, other sizes are still refused, and no other variant changes. KUnit covers the selection, the new variant's start fields, the per-boot word and the layout lookup.

Behaviour comes from the firmware the bootloader handed over (its reserved segment sizes and TEXT CRC), the same way the command layouts are already chosen. There is no board or chip gate and no new parameter.

Testing

  • Mac mini J473 (M2, 27.2), default fleet82 boot, default cmdline, one module swap: the encoder binds. gst v4l2h264enc/v4l2h265enc and ffmpeg h264_v4l2m2m/hevc_v4l2m2m gave 12/12 encodes, and two runs gave byte-identical bitstreams. The AVD hardware decode of every bitstream matched a software decode bit for bit (120/120 frames, 6/6 streams). PSNR at 8 Mb/s 1080p30: H.264 45.0 dB, HEVC 45.9 dB. Also tested: 4K, 720p (Main and Baseline), 1366x768, H.264 High with B-frames, and an encode after runtime suspend. No DART faults, no encoder errors, no AVC denials.
  • M2 MacBook Air (13.5 firmware), fleet82: same source and encodes with this module and with the stock module. All 6 bitstreams were md5-identical, so the 13.5 path is unchanged.
  • arm64 KUnit for drivers/media/platform/apple/ave: 47/47 pass at this head. The host ABI tests (run.py, run-recovery.py) pass. checkpatch --strict is clean.

Still to run

  • None for this change. AVD decode on J473 27.2 was already bit-exact on the default (H.264 8/10-bit, HEVC Main/Main 10, VP9 P0/P2, 60/60 each).
Row detail
  • E1 (J473, 09:31-09:37): fixed raw 1080p30 source (ffmpeg testsrc2, 120 frames). gst default rate: H.264 39.8 dB, HEVC 41.0-41.2 dB (the default HEVC stream has B-frames). Worst single frame 38.2 dB. Extra lavfi rows: 4K H.264 41.6 / HEVC 42.6 dB, 720p Main 44.3 / Baseline 43.1 dB, 1366x768 H.264 42.9 / HEVC 45.3 dB, after runtime suspend 45.2 dB.
  • E2 (J473, 10:31-10:40): video/x-h264,profile=high with video_b_frames=2 gave 86 B / 5 I / 29 P frames, has_b_frames=2, 40.7 dB. High with b=0 gave 40.6 dB. ffmpeg -profile:v 100 gave 45.0 dB. All three streams decode bit-exact on the AVD (120/120).
  • R1/R2 (M2 Air, 09:46-09:52): PR module vs stock module, 6/6 bitstreams md5-identical, run1 == run2 on both, AVD decodes 60/60 bit-exact.
  • After each row the Mac was put back on its default with a plain reboot and checked: the default kernel running and saved, next_entry empty, SELinux Enforcing.
  • Rows E1/E2/R1 ran the module built from 9842c441 against the fleet82 source and config. This head differs from it only in comments, KUnit and the commit message; the non-comment driver code is identical.
  • Method: references are ffmpeg n8.1.2 -f framemd5 software decodes on an x86 build host. PSNR is raw NV12 against raw NV12 at the same frame rate.

Assisted-by: LLM (Claude:Opus 5.5)

On an M2 Mac with the macOS 27.2 (26B123) stub, as on the Mac mini
(J473), the bootloader preloads a newer encoder firmware build than the
one the T8112 variant knows: TEXT 0x11c000 instead of 0xd0000, DATA
0x128000. The driver refused it at probe ("unexpected firmware segment
sizes"), so the encoder never registered. Like the M4's 27.2 loaders,
the Mac mini's sets the word at TEXT 0x4224 on every boot; with it
zeroed the TEXT CRC is 077a3444.

That build is the M2 encoder's build of the firmware version the M3
already runs on 27.2, and it starts the way the M3's does: the boot
configuration handshake as device 12 with handshake type 12, the 26B123
command layout and its reference buffer sizing (lfs_ref_scale 2, as on
the M3 and M4), the codec clocks ungated by clearing the mailbox idle
word, the bootloader's code base (marked valid) left in place, and DATA
restored from the boot snapshot before every start. None of the 13.5
build's start (device 18/type 15, the TEXT link cell, the extra0 window)
applies to it.

Describe it as its own variant and let a variant name the variant of a
later build of the same encoder (next_build). At probe the firmware
reservations the bootloader made select the build by their segment
sizes; the TEXT CRC then has to be that build's. Like the command
layouts, which the TEXT CRC already selects, this keys on the firmware
build because it must: the start and the command protocol belong to the
build the bootloader handed over, and only its segments identify it. The
13.5 build keeps its variant and start, other sizes are still refused,
and no other variant changes.

KUnit covers the selection (13.5 sizes, 27.2 sizes, near misses), the
27.2 variant's start fields, its per-boot TEXT word (any value gives the
zeroed-word CRC) and its layout lookup.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 4d459a4.

Thanks, this reads well. The build is picked from what the bootloader handed over (reserved segment sizes, then the TEXT CRC), inside the one apple,t8112-ave match, with no board test and no parameter, and both unknown cases stop the probe: other sizes fall back to the 13.5 variant and fail its size check (ave-fw.c:300-305), and 27.2 sizes with another CRC fail at ave-fw.c:354. Since the firmware can't be asked for its version before it runs, I think that's as narrow as this can be. Other encoders only see ave_fw_select_build() return the variant it was given (ave-fw.c:258-261). A few small points:

  1. ave-drv.c:86,91: where do device 12 and handshake type 12 come from? The 13.5 build of the same chip uses 18/15 and the M3 uses 17/17, so "starts the way the M3's does" doesn't cover the number. The T8142 comment (ave-drv.c:248-253) names its source (ADT soc-id, plus a traced boot). Could the commit message or the comment say the same for 12, for example a trace of the macOS 27.2 start on the J473, or the ADT?
  2. ave-abi-test.c:1515-1518: the near-miss cases only show that selection falls back to &ave_t8112. The refusal itself is in ave_fw_probe() and has no test, though the test's comment says "other sizes stay refused". Would it be simpler for ave_fw_select_build() to return NULL when nothing matches a variant that pins sizes, with the probe failing right there? Then the test could assert the refusal directly. Either way is fine with me.
  3. ave-fw.c:304-305: this message doesn't print the sizes, while the builds[] branch at ave-fw.c:295 does. Now that the M2 has two builds, could it print TEXT/DATA too, so a third build is easy to identify from a log?
  4. Optional: next_build is a second way to describe "one encoder, several builds" beside builds[]. I see why (the start differs, not only the CRC), and a line in the ave.h comment saying when to use which would help the next person.

Testing: I checked that the driver code at this head matches the tested 9842c441 apart from comments and KUnit, so the J473 and M2 Air rows carry over. Two rows would round it off: an encode on the J473 after a system suspend/resume (only runtime suspend is listed), and, since the shared 26B123 layout condition was edited (ave-layout.c:997-999), a probe plus one encode at this head on a J615 or J713. If another M2 board gets a 27.2 stub later (J413/J493), a probe row there would confirm the path where the loader leaves the 0x4224 word at zero.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pre-PR checklist (§1–§6) review at 4d459a41e9f9e5723f49cb61f2a2dceef83614e1.

Code & safety audit

  • drivers/media/platform/apple/ave/ave-drv.c:559-589 & ave-fw.c:239-290: Verified ave_probe() does not read any field of ave->variant before ave_fw_probe(), and ave_fw_probe() calls ave->variant = ave_fw_select_build(ave->variant, ave->text.size, ave->data.size) before reading text_crc, boot_qualified, build_count, or segment sizes.
  • ave_fw_select_build() walks the static next_build chain (ave_t8112 -> ave_t8112_26b123 -> NULL) by bootloader-reserved TEXT/DATA sizes and falls back to the head variant on near-misses, so unexpected sizes still fail closed with -EINVAL.
  • ave_t8112_26b123 (TEXT 0x11c000, DATA 0x128000, device/type 12, lfs_ref_scale = 2, text_boot_word = 0x4224, vcbar_flags = AVE_COPROC_VCBAR_VALID, mbox_idle = 0x38, restore_data_first = true, extra0_size = 0) and ave_layout_for_crc(AVE_FW_TEXT_CRC_T8112_26B123) -> &ave_layout_26b123 are consistent with the M3 27.2 build and ave_fw_text_boot_crc() bounds checks.
  • ave-abi-test.c: ave_t8112_26b123_build covers 13.5 selection, 27.2 selection, near-miss rejection, variant fields, per-boot word zeroing at 0x4224, and layout lookup.

Checklist summary (§1–§6)

  • §1 No model gating: Pass — selects strictly from bootloader-reserved firmware segment sizes + TEXT CRC (not chip/board/macOS-version checks); commit message documents why per §1.
  • §2 Production-ready: Pass — default command line, no module parameters, delays, or workarounds.
  • §3 Safety: Pass — fail-closed on unknown sizes/CRCs, bounds-checked text_boot_word, DATA snapshot restored cleanly.
  • §4 Clean-room & attribution: Pass — single commit 4d459a41e9f9 has human author/committer and human Signed-off-by: only, no AI trailers in commit, Assisted-by: at end of PR body.
  • §5 Evidence: Pass — J473 (M2, 27.2 stub, default fleet82 cmdline) 12/12 H.264/HEVC encodes (including 4K, 720p, B-frames, post-runtime-suspend) with 120/120 bit-exact AVD decodes, 0 DART faults, 0 encoder errors, 0 AVC denials (Enforcing); M2 Air (13.5 firmware) 6/6 md5-identical no-regression proof vs stock module; 47/47 arm64 KUnit + host ABI tests + checkpatch --strict clean at this head (driver code unchanged from 9842c441).
  • §6 Naming: Pass.
  • CI (holding approval here only): host-tests is currently in_progress on 4d459a41e9f9.

Zero code or policy blockers; holding APPROVE strictly until host-tests completes green on 4d459a41e9f9.

Assisted-by: LLM (Gemini 4 Neon)

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

host-tests is now green (SUCCESS) on 4d459a41e9f9e5723f49cb61f2a2dceef83614e1. All §1–§6 checklist gates pass (firmware-selected 27.2 build by reserved segment sizes + TEXT CRC, no chip/board gate, KUnit coverage, human-only commit trailers, strong J473 27.2 + M2 Air 13.5 HW proof). Approving for MERGETRAIN-LINUX4.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 4d459a4: no blockers.

Re-checked the single commit at this head. None of the four points from the earlier 4d459a4 review has an answer on the PR or a change in the tree (the head is the same commit), and none of them is a blocker:

  1. Device 12 / handshake type 12 (ave-drv.c:71-98): the source is still not named. The J473 encodes are bit-exact against software decodes, so the numbers are proven on hardware, but the comment says the build "starts the same way" as the M3's, and ave_t8122 uses 17/17. Please add one sentence naming where 12 comes from (ADT or a traced 27.2 start on the J473), the way the T8142 comment does. Non-blocking.
  2. Refusal test: still only the fallback to &ave_t8112 is asserted. By reading, a near miss such as TEXT 0x11c000 / DATA 0x12c000 falls back to ave_t8112 and fails its size check at ave-fw.c:300-305, and a 27.2 size with another CRC fails at the want_crc check. So the code fails closed; only the test comment ("other sizes stay refused") claims more than it asserts. Non-blocking.
  3. ave-fw.c:304-305 still prints no sizes. That is the message a third M2 build would hit, so printing TEXT/DATA as the builds[] branch does would help. Nit.
  4. next_build vs builds[]: ave.h now describes next_build, but not when to use it instead of builds[]. Nit.

Other checks: ave_fw_select_build() returns the variant it was given for every variant without next_build, and the ave_layout_for_crc() edit only adds a CRC to the 26B123 OR, so the T8122 and T8132 CRCs map to the same layout as before. Selection is by bootloader-reserved segment sizes and then the TEXT CRC, inside the apple,t8112-ave match: no board, chip or version gate, no parameter, default cmdline. No pointer-identity checks on ave->variant elsewhere. mergeable_state clean, host-tests green at this head.

Rows still owed (none posted on the PR since the earlier review):

  • J473: an encode after a system suspend/resume (s2idle). Only runtime suspend is in the rows.
  • J615 or J713: probe plus one encode at this head, because the shared 26B123 layout condition changed. By reading the change is additive for their CRCs, so I don't count this as a code blocker.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide merged commit a7638d5 into integration/aurora Nov 23, 2026
1 check passed
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Follow-up for the review at 4d459a4, pushed as e3cad61 (one commit on top, no force push):

  1. Device 12 / handshake type 12: the ave_t8112_26b123 comment now names the source the way the T8142 one does. The ADT names the chip (ave soc-id "t8112"), this build's device table numbers it 12/12, and the 13.5 build (ave_t8112) uses 18/15. The J473 rows confirm it: the start handshake completes and the encodes decode bit-exact.
  2. Refusal test: the plain size check in ave_fw_probe() now calls ave_fw_sizes_match(), the predicate ave_fw_select_build() already uses. It's the same expression, so no variant changes behaviour. KUnit now asserts the refusal itself: the near misses (0x11c000/0x12c000, 0x134000/0x128000) don't match ave_t8112 or the 27.2 variant, and the two real builds do. The test comment now says only what the test checks.
  3. Message: that refusal prints TEXT/DATA, like the builds[] branch.
  4. ave.h: says when to use builds[] (same start, different CRC/layout) and when to use next_build (a build that needs its own start fields and has its own sizes).

arm64 KUnit for drivers/media/platform/apple/ave passes 47/47 at e3cad61, the host ABI tests (run.py, run-recovery.py) pass, and checkpatch --strict on the diff is clean.

Rows at e3cad61. The module was built from this head's ave/ against the Mac's own default release, fleet82 or fleet81. The ave/ directory of both releases equals this PR's base.

  • M2 MacBook Air (13.5 build), fleet82: fresh boot, one module swap. 12/12 encodes, run 1 == run 2, and all 6 bitstreams are md5-identical to the stock module's, so the 13.5 path is unchanged. System suspend: 4 gst encodes, then one 15 s s2idle (rtcwake, rc 0), then the same 4 encodes, with byte-identical output before and after.
  • J615 (M3 Air, T8122 26B123 build, TEXT CRC 918d70d3), fleet81 default: this covers the shared 26B123 layout lookup this PR edits. Fresh boot, swap before any encode: the encoder binds, and gst H.264/HEVC (default and B-frames off, 1080p, 120 frames) gives 4/4 bitstreams md5-identical to the stock module on the same Mac.
  • 0 SError, DART faults or encoder errors, Enforcing, 0 AVC on both. Each Mac went back to its default with a plain reboot.

Still to run: the J473 encode after s2idle at this head. It's queued behind two other rows on that Mac.

Detail
  • J615 note: in the boot where I encoded with the stock module first, the PR module was then refused cleanly ("firmware data is not in its boot state", -ENODEV). That's the existing fail-closed rule: the encoder can't be re-probed once its firmware has started. So the PR-module encodes ran on a fresh boot and were compared with the stock encodes from the boot before. videotestsrc output is deterministic.
  • md5s (J615, stock == PR): H.264 default/b0 e6203389…, HEVC default 588e4e1f…, HEVC b0 2d043e3b….
  • M2 Air s2idle: wakeup on the PMU RTC, 16 s wall.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J473 row at e3cad61, the last one owed. Mac mini J473 (M2, macOS 27.2 stub), default fleet82 boot, default cmdline, one module swap built from this head:

  • The encoder binds. 12/12 encodes (gst v4l2h264enc/v4l2h265enc default and B-frames off, ffmpeg h264_v4l2m2m Main / hevc_v4l2m2m at 8 Mb/s, 1080p30, 120 frames) all exit 0, and run 1 == run 2. All 6 bitstreams are byte-identical to the 4d459a4-era rows in the PR description, and the AVD decodes all 120 frames of each.
  • System suspend: 4 gst encodes, then one 15 s s2idle (rtcwake on the PMU RTC, rc 0, 16 s wall), then the same 4 encodes. Output is byte-identical before and after.
  • 0 SError, DART faults or encoder errors, Enforcing, 0 AVC. The Mac went back to its default with a plain reboot.

With this row, every row asked for in review is posted at this head: J473 27.2 (encode + s2idle), M2 Air 13.5 (stock-identical + s2idle), J615 26B123 (stock-identical). @DjDeveloperr, your approval was at 4d459a4. e3cad61 only adds the review follow-ups (comment, predicate reuse with the same expression, sizes in the refusal message, KUnit), so please re-check it at this head.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Correction to my two comments above: this PR was merged at 4d459a4 before e3cad61 reached the branch, so the follow-up commit is not in integration/aurora. It's now #2938 (the same commit, with the rows above). The merged code here is unchanged by it apart from the refusal message, which now prints sizes.

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.

2 participants