Skip to content

Boot without SPTM: Mach-O boot object and EL1 OS handoff - #29

Merged
RyanTheTide merged 6 commits into
mainfrom
feat/macho-boot-object
Oct 31, 2026
Merged

RyanTheTide merged 6 commits into
mainfrom
feat/macho-boot-object

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

kmutil configure-boot without --raw records the size of the boot object's __TEXT_BOOT_EXEC segment as kcbz. macOS 27.2 iBoot loads TXM, ExclaveOS and SPTM, and enters SPTM, only when kcbz is nonzero. With kcbz 0 it jumps to the object's entry, as it does in raw mode. This gives M4 and later, including the A18 Pro, the same Stage 1 as raw mode, with GXF writable as on M1 to M3.

That boot leaves the secondary CPUs confined at EL2, so this PR also runs the OS at EL1 under a resident Aura.

What changes

  • New output: make also writes build/aura-boot.macho. It is build/aura.bin wrapped in an MH_FILESET with no __TEXT_BOOT_EXEC, built by tools/macho_boot_object.py.
  • Same bytes, same entry: the raw image is carried byte for byte in __TEXT_EXEC, 64 KiB after the load base. Every segment is file-backed at its virtual offset. The entry point is the raw image's own entry, the one --entry-point 2048 selects in raw mode.
  • Filled Stage 1: the tool can wrap a Stage 1 whose configuration block is already filled in. A filler can also still find the block by its magic inside the boot object.
  • Releases: Stage 1 release archives include aura-boot.macho. The details are in docs/macho-boot-object.md.
  • EL1 OS handoff: src/el1_os.c, described below.
  • T8140 clears the PMU failed-boot count, as T6040 does. Repeated test resets otherwise end in recoveryOS.

Why the OS runs at EL1

iBoot leaves four CTXR windows armed and locked on the secondaries. The boot CPU reports the same bounds with enforcement off. On T8140:

Secondary at Inside CTXR_D Outside it
EL2 executes instruction abort, ESR 0x8600000c
EL1 instruction abort to EL2, ESR 0x8200000c executes

Reads and writes inside the window worked at EL1 with the MMU off. I have not measured them with the MMU on.

Aura stays at EL2 and enters the OS at EL1 on every CPU. There is no build option: at kboot, el1_os_required() asks a secondary to run two instructions from the heap, and only a fault selects EL1. el1_os_enter() leaves EL2 as init_el2_state and finalise_el2_state would for the features this chip has (SME2, FGT, HCX, LOR). It has no SVE, GCS, MTE, MPAM, AMU, SPE, TRBE or BRBE, and its PMU is IMPDEF.

CTXR_D starts 0xd8000 below Aura's base, and kboot only reserved from the base up, so about 448 KiB of it was free for Linux. Executing there from a secondary aborts to EL2, which reboots the machine. kboot now reserves it in this mode.

Boots before that reservation died with SIGSEGV storms, kernel faults and instant reboots once userspace got busy. Boots with it have not. I did not catch Linux using a page in the window, so that link is inferred. #15 reports write faults in the same place on J813, which would also explain the SIGSEGVs. This is a separate fix from #15: its CTRR_D registers read 0 in this mode.

KVM is not available in this mode yet. Nested virtualization will follow.

Layout

These are kmutil's requirements, found by reading its tag derivation:

  • __TEXT must be at file offset 0.
  • __TEXT_EXEC, __PRELINK_INFO and __LINKEDIT are required.
  • __TEXT_BOOT_EXEC, __DATA_SPTM and __RECEIPT_INFO are optional.

The fileset also has __PRELINK_TEXT with a com.apple.kernel member header, an empty __DATA page and an empty chained-fixup table.

Tested

On a MacBook Neo (T8140, J700), with a proxy Stage 1 built this way and this Stage 2 chainloaded over USB. The tested image is byte-identical to this branch's build.

  • Two boots of this exact image and one of an earlier build reached a login from the installed Fedora 7.3.0-5 kernel, through U-Boot, GRUB and the LUKS prompt. CPU: All CPU(s) started at EL1, 6 CPUs, paca, pacg and sme2 present, no arm64.nopauth.
  • 40 seconds of file hashing and process spawning on all cores: 0 coredumps, 0 kernel faults, 0 failed units. An earlier build also came back from an s2idle suspend.
  • apple_sep loads at EL1. Trusted keys work and /dev/sep-bio appears. This model has no fingerprint sensor.
  • WFI wipes the general registers, the vector registers and NZCV at EL2, EL1 and EL0 on E and P cores. FPCR, SP_EL0 and the 33 tracked system registers survive, including the PAC keys. WFE wipes nothing. The kernel's existing apple_cpu_wfi covers idle.
  • tests/python/test_macho_boot_object.py: 7 pass. kmutil inspect gives kcbz : 0 with kmutil from macOS 27.2 and 26.6.2.

Not tested

  • A raw boot with this code. The runtime check should leave it at EL2.
  • A filled Stage 1 loading Stage 2 from the ESP.
  • Any chip other than T8140. el1_os_required() returns false on them.
  • A userspace wfi. It should lose registers on any Linux here, since these measurements cover EL0 and Linux does not trap EL0 WFI. That is a kernel issue separate from this PR.

🤖 Generated with Claude Code

kmutil configure-boot without --raw records the size of the boot object's
__TEXT_BOOT_EXEC segment as kcbz. macOS 27.2 iBoot loads and enters SPTM
only when kcbz is nonzero; otherwise it jumps to the object's entry as it
does in raw mode.

make now also writes build/aura-boot.macho: build/aura.bin wrapped in an
MH_FILESET with no __TEXT_BOOT_EXEC. The raw image is carried byte for
byte in __TEXT_EXEC, every segment is file-backed at its virtual offset,
and the entry point is the raw image's own entry, so the code is the same
as in raw mode. tools/macho_boot_object.py can also wrap a Stage 1 whose
configuration block was already filled in. Stage 1 release archives
include the boot object.

kmutil from macOS 27.2 and 26.6.2 parses it and derives kcbz 0. Not yet
cold-booted on hardware.

Assisted-by: Claude Opus 5.5
iBoot counts failed boots in the PMU and drops to recoveryOS once the count
gets too high. A proxy test loop on the Neo reached 3 within minutes, and
nothing else in that chain clears it. Clear it as on T6040.

Assisted-by: Claude Opus 5.5
@DjDeveloperr DjDeveloperr changed the title Build a Mach-O boot object that iBoot enters without SPTM Boot without SPTM: Mach-O boot object and EL1 OS handoff Oct 31, 2026
A boot object with kcbz 0 skips SPTM, but iBoot leaves CTXR windows armed
and locked on the secondary CPUs. On T8140 they confine EL2 execution to the
boot object, so Linux cannot run at EL2: its secondaries fault as soon as
they are released.

Add src/monitor.c. Aura stays resident at EL2 and enters the OS at EL1 on
every CPU. It decides at kboot by asking a secondary to run code from the
heap, so there is no build option and a boot without these windows should
keep entering the OS at EL2. It leaves EL2 the way the kernel's init_el2_state
would, for the features this chip has.

At EL1 the windows invert: executing inside CTXR_D aborts straight to EL2.
CTXR_D starts 0xd8000 below our base, where kboot left memory free, so reserve
it. Without that reservation Linux died with SIGSEGV storms, kernel faults and
instant reboots once userspace got busy. With it the Neo boots to a login and
stays up under load.

CTXR_D is not the CTRR_D of #15: those registers read 0 in this mode.

Assisted-by: Claude Opus 5.5
@DjDeveloperr
DjDeveloperr force-pushed the feat/macho-boot-object branch from 0f0ca08 to 429c5d9 Compare October 31, 2026 11:03
Preserve the Stage 1 boot-record read before clearing the T6040 and T8140 failed-boot count, and include both release documentation lists.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Keep the chainload and kboot harnesses in sync with next_stage and monitor_required. Check that chainloading clears a previous monitor request and that kernel handoff publishes the runtime decision.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
GCC -O2 now places essential Stage 1 code and data beyond the DCP log-buffer boundary on current main. Use the same size optimization as the build workflow for normal and release builds, retaining the linker guard and the EXTRA_CFLAGS override.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide merged commit 999b72e into main Oct 31, 2026
11 checks passed
@RyanTheTide
RyanTheTide deleted the feat/macho-boot-object branch October 31, 2026 12:19
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