Skip to content

The boot chain, in C

The iPod classic boots in stages, and each stage loads and checks the next one. Chikuma reproduces both stages that run before the operating system, in C, and the same reproduced chain boots Apple's unmodified firmware to a working interface.

The three stages

cold boot   ROM  ->  NOR bootloader  ->  the OS from the disk's firmware partition
recovery    ROM  ->  USB DFU  ->  recovery image  ->  USB DFU  ->  whatever the host sends

The mask boot ROM

The processor runs this code first. The ROM sets up the earliest clocks and reads a pair of pins to decide where to boot from. On a normal cold boot it loads the NOR bootloader, verifies it and jumps to it.

When there is nothing valid to load, the ROM falls through to a USB device firmware upgrade (DFU) loop and waits for a host to send it an image. The reproduction lives in chikuma/bootrom/, built from source.

The NOR bootloader

Apple's bootloader is an EFI firmware in miniature, and Chikuma reproduces it as roughly forty modules in chikuma/onb/. The familiar EFI phases are all present: security, pre-EFI initialisation, driver execution, boot device selection and the hand-off.

The bootloader reads the NOR image directory, then verifies and decrypts the next stage. It brings up main memory and the rest of the clocks, and it draws the early boot screens. Then it reaches the operating system on the disk's firmware partition.

The operating system

This is RetailOS itself, the subject of the rest of this documentation.

The recovery path

A host can also push a small recovery image to the ROM's USB DFU loop. Apple calls that image the WTF. It brings up the clocks and memory, then runs the ROM's DFU code a second time, with its own load window, to receive whatever the host sends next.

From the host's side the two DFU sessions look the same, which matters when driving either one. The WTF has the detail, and chikuma/wtf/ reproduces it in Zig.

Reproduced from source

Every stage is a C reproduction written from source, and none of them is a modified copy of Apple's binary. The chain is signed with Chikuma's own certificate chain instead of Apple's keys. The whole sequence runs on the emulated machine: NOR read, signature check, decrypt, the EFI phases and the hand-off.

Booting Apple's unmodified firmware through this same chain is the control. If a stage were subtly wrong, the original would fail at the spot where Chikuma happened to tolerate it, and it reaches a working UI.

Out of scope

This site covers the boot chain as architecture. It does not document Apple's cryptography, key material, or any exploit of the boot ROM. The security internals of a shipping product are no part of a clean-room reimplementation.

On a real iPod

The reproduced bootloader sits in the flash of the project's development unit, a real iPod classic, and runs there at every boot. It does what Apple's does: it brings the machine up, draws the boot screens and picks what to start. Three differences are Chikuma's, and declared as such.

Difference What the bootloader does
Boots Chikuma beside RetailOS Chikuma's OS has its own entry in the disk's firmware partition, next to Apple's, and the bootloader checks it against Chikuma's own key before starting it. Apple's unmodified OS still boots through the same bootloader.
Chikuma's disk mode first When the reboot reason asks for disk mode, it looks for Chikuma's disk-mode image before Apple's.
Chikuma's boot screens The logo and the charging, low-battery and failure screens in flash are Chikuma's own pictures, drawn by the bootloader's own JPEG decoder.

On silicon the cache has to be cleaned on every way, the bootloader must wait out an AES job, and timer interrupts arrive on two lines instead of one. The reproduction handles all three, and the emulator models the ones it can. Bring-up on a real iPod walks the sequence from power-on to the OS.

Installing the chain on a device

Getting the chain into a device is developer plumbing and no product. It touches flash on a device that is no longer manufactured, so read On the device before going anywhere near real hardware.