Boot flowDraft
This page follows one power-on from the moment iBoot starts OpenBoot to
the moment a guest operating system runs. The flow is the same for every
device; the values that differ are read from the device tree and from the
device's descriptor. Where a step has only been observed on one machine,
it is described on the page of that generation, today the
M5 boot page; results are on its
status page. This page describes what the code does; it is not a
tutorial. The order below is the order of openboot_main() in
openboot/src/main.c.
The stages#
| Stage | Where it runs | What it does |
|---|---|---|
| iBoot | Apple firmware | Loads the OpenBoot object and passes control to it, with the device tree (ADT) and the boot arguments. |
| OpenBoot | EL2, main core | Sets up memory, interrupts and secondary cores, decides whether a debug host is attached, shows the menu or autoboots. |
| EL2 layer | EL2, every guest core | Stays resident under the guest and emulates what the guest expects but the hardware does not provide. |
| UEFI | EL1, under the EL2 layer | The EDK II firmware that OpenBoot launches; it finds and starts the operating system loader. |
| Guest OS | EL1, under the EL2 layer | For example Windows on Arm. |
OpenBoot starts at exception level 2 and stays there: the
hold window and the menu run at EL2, and the guest is
entered at EL1 afterwards. The banner printed first says
Running in EL2 when this is the case.
What OpenBoot does before the menu#
The main core runs these steps in order. Some steps are compiled out of special builds.
- Adopt the persistent log area and print the tail of the previous boot's log. A hang that ended in a reset therefore leaves its last lines on the next boot's console.
- Print the banner (
openboot <version>, the GPL notice and the current exception level). - Read the boot firmware version from the device tree and initialise the heap.
- Enter the guarded execution mode when the CPU supports it, then initialise the memory controller, the MMU and the interrupt controller (AIC).
- Select the debug mode and bring up the secondary cores. The last CPU in the device tree is held back for the debug core; see the next section.
- Disable the SoC watchdog and initialise power management.
- Print why this boot happened, as far as iBoot says (read only).
- Run the hold detection (next section).
- Depending on the verdict, start or release the debug core, and reserve the sideload window.
- Stage the firmware descriptor that travels inside the boot object.
- Initialise the display and the framebuffer and show the logo; fix up CPU frequency tables and the secure enclave interface.
- Start the boot UI. With a debug host attached the main loop runs with autoboot off; otherwise the menu and the stored settings decide what starts.
- Prepare the next stage: shut down the internal storage controller and exception handling, display and framebuffer, and the MMU, then jump.
The hold window#
Before any storage command is sent and before the display is touched,
OpenBoot decides whether a host is waiting for it. The module is
openboot/src/dbg_hold.c; the decision itself is a pure function in
hold_decide.c, so it is covered by host tests.
In the plain-USB mode (hold mode 1, the one the OBLink link uses) the sequence is:
- OpenBoot brings up a CDC-ACM gadget on the debug USB port.
- It waits for a USB bus reset. If none arrives within the connect window
the verdict is
dark. If the port controller reports that no plug is present the verdict isdarkat once. - After a bus reset the host must open the serial port, which raises the
DTR line. If this handshake does not arrive within the handshake
window the verdict is
darkas well: a reset alone only proves that something is a USB host, not that it speaks OBLink. - With the handshake the verdict is
debug.
| Verdict | Meaning |
|---|---|
dark |
No host. The boot continues as configured, and the debug core is never started, so its CPU goes to the guest. |
debug |
A host is present. The debug core and the monitor start, autoboot is off and the host drives the boot. |
The default connect window is 1500 ms and the default handshake window is
4000 ms (HOLD_CONNECT_MS and HOLD_HANDSHAKE_MS in hold_decide.h).
The hold mode, the window and a few more switches can be changed without a
new build through the ob-hold NVRAM setting
(<mode>,<arm>,<window ms>,<poll>, every field optional). The build
default for the hold mode is a compile-time option (OB_HOLD_PLAIN),
and its default in openboot/Makefile is 0, so the plain-USB hold below
applies to a build made with OB_HOLD_PLAIN=1 or to a machine whose
ob-hold setting selects mode 1. Mode 0 keeps an older detection path
(any bus reset, or a debug-USB message from the port controller, holds)
that this documentation does not describe. Mode 2 is a hybrid: that older
message holds at once, and a bus reset without it needs the handshake.
A build made without an OB_HOLD_PLAIN argument therefore uses mode 0, not
the plain-USB hold. The images built for the project's own OBLink runs
select a mode explicitly, so their flags differ from a default build; the
hold window (OB_HOLD_WIN_MS, default 1.5 s) can also be set at build time.
An installed boot object keeps the flags it was built
with; to see which mode is in force on a running machine, read the mode=
field of the hold line that the monitor's info command prints.
The hold writes a one-line record of what it saw (verdict, mode, the port
controller status, whether a bus reset and the handshake were seen, and
the reason). The monitor's info command prints it, and the console
prints it again once the debug core is up, so a host that attaches late
can still read it. See the hold verdict.
A debug boot ends when the host sends boot auto (the stored settings
policy then runs after the usual delay) or loads and launches something
itself with the monitor, for example uefi launch or sideload image.
The EL2 layer#
The guest runs at EL1. EL2 stays resident under it for the whole boot
(el2_guest.c, el2_stage2.c). It exists because Windows and standard
UEFI expect hardware that Apple silicon does not have, and because some
devices must be shared or protected:
- Stage 2 translation. An identity map (guest physical address equals host physical address) built from the device tree's DRAM range. The DRAM window comes from the device tree; the descriptor of the board holds a fallback for it. Everything below the DRAM window is mapped as device memory. A few pages are made execute-never so that selected guest events fault into EL2.
- Interrupt controller. The guest sees a GIC-style interrupt
controller (distributor and redistributors) that EL2 emulates
(
el2_vgic.c) on top of the hardware List Registers; the physical controller is Apple's AIC. - Virtual CPUs. One per guest core. PSCI
CPU_ONandCPU_OFFfrom the guest are served by EL2 (el2_smp.c); the cores themselves are already up before the guest starts. - Trapped devices. Where the hardware has no model the guest's
driver can use, stage 2 traps accesses and EL2 emulates them: a virtual
xHCI controller for keyboard and mouse input (
el2_vxhci.c) and a mediator in front of the internal NVMe controller (el2_nvme_med.c). USB ports can also be passed to the guest through DART with stage-2 holes (el2_usbpt.c). - Periodic work. A per-CPU timer tick runs the services that need an
EL2 host (
el2_work.c). - Power requests. A PSCI
SYSTEM_RESETfrom the guest ends in a machine reset after the storage controller has been shut down in order. There is no true power-off path yet:SYSTEM_OFFhalts the guest and parks the machine on a panel that asks to hold the power button (an image in which the guest owns the GPU resets the machine instead). A build option (GUEST_RESET_HOLD) parks the guest on either request instead, so a developer can inspect the machine.
Hardware that Windows already has a driver model for is handed to the guest as it is; the EL2 layer emulates only where no such model exists.
UEFI#
uefi_launch.c prepares the launch. The firmware (an EDK II firmware
descriptor, OPENBOOT.fd) is either embedded in the boot object next to
the OpenBoot image or placed in DRAM by a host. OpenBoot builds a
versioned handoff record from the live device tree (memory layout, frame
buffer, interrupt controller, CPUs, the boot policy) and enters the
firmware's SEC phase with the record's address in x0. There is no way
back from this point: the menu task is abandoned with interrupts masked.
The monitor's uefi launch command starts UEFI in mode 1 by default
(guest at EL1 under the EL2 layer); mode 2 is a legacy EL2 jump.
The handoff carries a boot target, which the firmware's boot manager uses
to pick the volume: auto, internal, removable or menu. With a
named EFI system partition the firmware starts, in this order, the loader
path stored with the default, \EFI\Microsoft\Boot\bootmgfw.efi, and
\EFI\BOOT\BOOTAA64.EFI. The details of the stored default are in
Menu and settings.
The guest OS#
After ExitBootServices the operating system owns the machine, with the
EL2 layer underneath. OpenBoot's own console output and the guest's debug lines land in one
persistent log ring; with a debug host attached, the monitor's log
command reads its tail.
Not verified#
- The exact content of the boot arguments iBoot passes and how the object is installed are not described here.
- This page was written from the code and has not been checked on hardware in a documentation pass.