iPhone Boot Chain (Note)
Boot chain

SecureROM
SecureROM is the first code the CPU (the Application Processor - the A-series chip) runs the moment it has power, at EL3 (the highest privilege). PC jumps to its address in the reset vector.
The code is written straight into the silicon at manufacture and cannot be patched by a software update. The A5-A11 chips are permanently vulnerable to checkm8.
There are 3 boot paths:
- SecureROM loads LLB and then iBoot (on A10 and later it loads iBoot directly). If the env var
auto-boot=true, iBoot runsboot-command=fsbootand loads the kernelcache withroot=fsys(using the kernelcache in the real filesystem on NAND). Ifauto-boot=false, it does not boot on its own and switches to iBEC (recovery mode). - OTA update: the update comes over the internet and sets
boot-command=upgrade(the only command iBEC accepts), iBoot switches to iBEC, and iBEC loads the kernelcache with theroot=upgradeDMG to install the update. - DFU, recovery: either the user holds the GPIO keys side + home/volume while powering the device on, or SecureROM cannot load the next stage (failure). The device enters DFU and waits for the USB host to send the iBSS image, then on to iBEC, then to the kernelcache with the
root=recoveryDMG (the restore ramdisk, a mini OS that sits in the IPSW and is loaded into RAM) to restore the device. The USB host only supplies the IPSW and watches the progress, the ramdisk does the real work.
The SecureROM version matches the iBoot version at the time the chip was manufactured. The host can read this version from the serial number while the device is in DFU mode.
Common code

The boot components share a large part of their codebase and do some of the same work:
- Rebase loop: check whether the code is loaded at the VA assigned to it beforehand, and if not, move the code there by copying it.
- Platform bootstrapping: bring up the CPU, the vector base address register (
VBAR), the MMU and the ARM MSRs. - Task management, multithreading: mainly for iBoot.
IMG3/IMG4decoding.- Certificate handling: holds a hardcoded certificate and the DER code to verify images with the public key.
On newer devices there are still nominally 4 images, LLB, iBoot, iBEC and iBSS, but in reality a single iBoot image handles every phase.
Chain of Trust
The hardcoded root certificate is already written in the ROM and cannot be changed -> it becomes the root of trust -> SecureROM verifies iBoot -> iBoot verifies the kernelcache.
The certificate in the ROM can be dumped.
Boot partition
On newer devices the boot components can be updated (iBoot, the Apple Device Tree - the structure that describes the hardware tree - the logo, and so on), and they are copied from the IPSW into the boot partition (the second NVMe namespace, the first one holds the root filesystem and the user data).
IPSW — separate files Boot partition
┌─ Container IMG4 ────────────┐
iBoot / LLB ─────────────────────►│ illb: bootloader │
DeviceTree ──────────────────────►│ dtre: hardware description │
Logo ────────────────────────────►│ logo: the apple image │
Battery, recovery images… ───────►│ bat0, batF, recm… │
APTicket ────────────────────────►│ signed authentication data │
└─────────────────────────────┘For a bootloader that is still encrypted, SecureROM has to decrypt it with GID when loading it in order to run it.
DFU mode
DFU = Device Firmware Update, entered when SecureROM cannot carry on booting. DFU is a USB standard with public documentation.
Every device has a device descriptor (a number) that describes the device in general: the vendor ID, the product ID and the index values that point to the string descriptors:
- iManufacturer.
- iProduct: in DFU it is “Apple Mobile Device (DFU Mode)”.
- iSerialNumber:

CPID: the chip ID, which SoC this is.CPRV: the revision of the chip.CPFM: fuse - there are 3 levels.ECID: the identifier of each individual chip, used when requesting an APTicket from Apple.
Demotion
Lower the fuse from production -> development, temporarily, until the next reboot. It opens up the JTAG/SWD debug interface and allows debugging the AP and the SEP directly.
A retail device has CPFM = 03, a development device has CPFM = 01 or 00. The fuse is written in hardware -> it cannot be changed. But the value is loaded into an MMR (and that value can be changed).
checkm8 and usbliter8 can overwrite that MMR -> demotion.
Debugging also needs a dedicated cable: Kong, Kanzi, Bonobo, Tamarin.
iBoot
It is the second stage boot loader (iBootStage2). Its main job is to find and load the kernelcache.
It runs many tasks (or threads) in parallel. Many tasks handle async events such as the USB events. For example:

The task structure is preinitialized with the magic stak.
Env var
The RELEASE build of iBoot only allows setenv or getenv on a very small set in NVRAM, limited by a whitelist. For example:
auto-boot: boot automatically according toboot-command, or go to recovery.boot-command:fsboot,upgrade,recover.
When running fsboot, iBoot reads boot-path, boot-device and boot-partition to know where to mount the root fs. It needs a filesystem driver: HFS+ (up to iOS 10.3) or APFS (after that).
Default boot-path = /System/Library/Caches/com.apple.kernelcaches/kernelcache, though the default boot-device varies by device type (nand0, asp_nand0 or nvme_nand0). Because neither of these values is in the environment variable white list, the defaults are also the only options for RELEASE builds.