Skip to content

The boot chain

Between reset and the first instruction of RetailOS, the iPod runs two other programs: the boot ROM in the chip, and the ONB, Apple's secondary loader in NOR flash. Each one checks the next before it jumps. Chikuma replaces both and still starts Apple's own firmware.

This page is the reverse engineering, read out of the images. What Chikuma built from it, a boot ROM and an ONB written entirely in C, is in The boot chain, in C.

graph TD
    R["Reset<br/>0x20000000"] --> BM["bootrom_main<br/>0x20003458"]
    BM --> BC["boot_context_init<br/>reads GPIO group 3, pins 6/7"]
    BC -->|mode 1/2| NOR["boot_from_spi_nor<br/>0x20002fa8"]
    BC -->|mode 3/4| NAND["boot_from_nand"]
    BC -->|no image found| DFU["USB DFU loop<br/>dfu_command_dispatch"]
    NOR --> V1["dfu_verify_signature<br/>+ dfu_header_verify"]
    V1 -->|ok| JMP["jump_to_image<br/>0x200034a0"]
    V1 -->|fail| DFU
    JMP --> ONB["ONB: SEC → PEI → DXE_CORE → drivers → BDS"]
    ONB --> BDS["onb_bds_boot_candidate_policy<br/>tries osos, osr3, diag, wtf, aupd…"]
    BDS --> OS["RetailOS, on the disk's FAT16 firmware partition"]

The boot ROM picks a device from GPIO

bootrom_main starts by zeroing its own stack frame. That frame is BootContext, the one structure the whole ROM passes around. Then boot_context_init reads two GPIO pins and picks a mode.

Mode Pins Path
1 group 3, pins 6/7 = 00 boot_from_spi_nor(0)
2 boot_from_spi_nor(2)
3 boot_from_nand(0)
4 boot_from_nand(1)

On the iPod Classic 6G both pins float low. That selects mode 1, the only path this device ever takes.

The ROM reads, verifies, decrypts and jumps

spi_flash_read_image(bus, 0x800, 0x22020000, 0)     the container header
dfu_verify_signature(header, mode=2)
if header.enc_type in {1, 2}:
    spi_flash_read_image(bus, header.data_sz, 0x22000000, 0x8800)   the body
    dfu_header_verify(header, 0x22000000, 1)        verifies AND decrypts in place
    jump_to_image(BootContext[0x30] + 0x22000000)

The header sits at NOR offset 0x8000 and the body at 0x8800, which is exactly where the ONB lives. So on a normal boot the ROM loads the ONB to 0x22000000 and jumps into it.

dfu_header_verify hashes the header and the body together, and the leaf signature covers that digest:

digest    = SHA1(header[0:0x800] || body[0:round16(data_sz)])
signature = right after the body, at data_sz rounded up to 16   (0x80 bytes, RSA-1024)

The certificate chain

The chain is plain DER. dfu_x509_chain_and_sig_verify looks for 30 82 <len>, an ASN.1 SEQUENCE with a long-form length, at the front of the chain blob. It then slices up to three certificates back to back, each by its own encoded length.

The root anchor is a literal 20-byte SHA-1 digest in the mask ROM (root_public_key_blob+1088). A root certificate passes only if it hashes to that exact value, and no fuse or field can change it. Subject names such as /CN=Apple Secure Boot Certification Authority decide which slot is root, intermediate or leaf. Every one of them still goes through the RSA check.

The ONB is a small UEFI environment

The ONB looks nothing like a typical embedded bootloader. Its body is an EFI Firmware Volume, with the _FVH signature, a real block map and a real header checksum. It carries 42 FFS files.

File What it is
SEC / SECURITY_CORE a TE image, the first code to run
PEI_CORE the pre-EFI stage
DXE_CORE its GUID matches EDK2's DxeMainDxe byte for byte: Apple's build of Tiano's reference core, for ARM
38 drivers a few stock EDK2 ones (DiskIoDxe, PartitionDxe), most written by Apple
graph LR
    SEC["SECURITY_CORE<br/>TE image"] --> PEI["PEI_CORE"]
    PEI --> DXE["DXE_CORE<br/>= DxeMainDxe"]
    DXE -->|dispatches| DRV["38 drivers:<br/>ATA, LCD, DiskIo, PartitionDxe,<br/>IpodFirmwareFS, the ROM/BDS policy…"]
    DRV --> BDSMOD["Bds.efi"]
    BDSMOD --> POLICY["onb_bds_boot_candidate_policy"]

BDS picks a boot candidate

onb_bds_boot_candidate_policy tries named candidates in order. osos (RetailOS), osr3, diag, dfup, rsrc and bdhw are among them. Each name goes through the standard EFI file API:

Find(name):
    LocateHandleBuffer(ByProtocol, EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, &count, &buffer)
    for each handle in buffer:
        HandleProtocol(handle, &SFS_GUID, &sfs)
        sfs->OpenVolume(sfs, &root)
        root->Open(root, &file, name, EFI_FILE_MODE_READ, 0)
        if success: break
    return file (or NULL)

Nothing routes by drive letter and there is no custom index at this layer. Find simply asks every volume that speaks the filesystem protocol, in whatever order LocateHandleBuffer gives them.

The one filesystem BDS can see

Only one driver in the ONB produces EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. That is IpodFirmwareFS.efi, over the Apple_MDFW/iPod_Firmware partition. The FAT16 resources volume and the HFS+ data partition have no driver at this stage, so BDS cannot see them.

The volume is a flat index of twelve 40-byte entries, with no directories and no allocation. Open() and Read() walk the same entries.

Offset Size Field
0x00 u32 the medium the entry lives on: "ATA!", "FNor", "NAND" or "flsh"
0x04 u32 4-byte ASCII name, packed big-endian ("osos" = 0x6f736f73, stored 73 6f 73 6f)
0x08 u16 type/flags. 0xFFFF (erased) marks an unused slot, skipped even on a name match
0x0a u16 data offset, high 16 bits
0x0c u32 data offset, low 32 bits, partition-relative
0x10 u32 length in bytes

Read as little-endian words, Apple's disk entries are tagged "ATA!", which is why a hex dump shows !ATA. Open() compares a UCS-2 string against the decoded 4-character name, so it can only ever resolve a 4-character request.

Where the index sits

That depends on the medium underneath.

Medium Banner check Index offset
disk (has a block device) the partition must open with a "STOP screen" copyright banner read from the header, 0x5000 on Apple's partition
NOR (no block device) none fixed, 0xffe00

On the NOR, only the "flsh" medium is accepted. On the disk, the header bytes are identical between the pristine ipsw bundle and a built disk.

The field roles are measured twice. The read code adds the position to the 48-bit value at +0x0a/+0x0c and limits it by +0x10. And under that reading, Apple's four entries chain exactly, each one starting on the first 4 KiB page past the previous one's end:

Name Offset Length
rsrc 0x6000 0x4e00000
osos 0x4e07000 0xa06aa3
aupd 0x580f000 0x11c8d3
hash 0x592d000 0x1000

Apple's index already names osos and points it at a real enc_type 3 container. Nothing in the index or the loader has to change for osos to boot.

If the osos read returns only zeros, osos never becomes a live file object. The "8702" magic compare then fails, and BDS falls through to the restore screen (below).

How a Chikuma image joins the index

The disk image build puts Apple's firmware bundle in verbatim, with its index intact. A Chikuma-signed enc_type 3 image goes into the first free slot, one page past the end of the last image, the way Apple lays out its own entries. So it never writes over osos or aupd. An image already in the index is replaced in place.

The MicroShell debug hook

Before any named candidate, onb_bds_boot_candidate_policy always runs a debug hook. It tries to load C:/MicroShell.fv, an engineering tool in the style of the EFI shell, under Apple's own internal name.

graph TD
    A["LocateProtocol(MicroShell resolver GUID)"] -->|NULL| X["return, clean"]
    A --> B["resolver(this, L#quot;C:/MicroShell.fv#quot;)"]
    B -->|NULL| X
    B --> C["bounds check: file size vs FV window"]
    C -->|fail| DL["CpuDeadLoop(), hard hang"]
    C -->|ok| D["HandleProtocol"]
    D -->|status<0| DL
    D --> E["build MEDIA_PIWG_FW_FILE_DP path node"]
    E --> F["LoadImage(BootPolicy=TRUE, …)"]
    F --> G["StartImage(handle, NULL, NULL)"]
    G --> H["return, unconditionally, status never checked"]

The 42-file volume contains no call to EFI_SECURITY_ARCH_PROTOCOL or EFI_SECURITY2_ARCH_PROTOCOL, so this path has no authentication to fail. It stays out of reach anyway. IpodFirmwareFS.efi, the only filesystem the ONB sees here, matches names against a 4-character field, and "C:/MicroShell.fv" is 17 characters long. It cannot match any entry on any partition. The hook is a leftover from an engineering build, with no way to fire in a shipped one.

What BDS does when nothing boots

This sequence was measured on a live boot, with hooks on Stall, a call ladder in Bds and QEMU's MMIO trace, so it is the ONB's behaviour and not the emulator's.

  1. Every candidate has failed. BDS writes the -------- reboot reason.
  2. It reads the PMU status through DxePcf50635. Bit 2 is PMU register 0x12 bit 2, the data-host detect (power source 3).
  3. With no computer attached, it draws the bdsw picture from the flsh directory. It polls the bit every 100 ms for 10 s, and leaves early if a host appears and holds for two reads. Then Display(1), Power(0).
  4. With a computer attached, it skips the wait, tries the disk candidate, draws bdhw and stalls 30 s. Then the same Display(1), Power(0).

Power(0) is DxePcf50635's 0xbeec5aa. It writes PMU register 0x0c := 1 (PCF5063x OOCSHDWN.GOSTDBY, power off) and spins forever. The "terminal halt" at 0xbeec5d8 is the firmware waiting for the PMU to cut its power.

bdsw is the restore prompt:

The ONB's restore screen, captured from QEMU

The seven flsh pictures sit as ciphertext in the NOR. The ONB decrypts and decodes this one itself, with DrawJpeg.efi and JpegDecoder.efi. CASET/RASET set a window, and the ONB writes the picture to the panel through the LCD controller's WDATA port, one pixel per write: a whole-panel white fill by DMA, then a 176x116 window for the text.

RetailOS never draws this way. It streams frames through the display pipe. The QEMU display shows the pipe, and the panel's memory whenever the pipe is idle (devices/lcd.c models the write window, devices/pipe.c the fallback).

Chikuma's version of the chain

Neither stage is a patched copy of Apple's images. Each ONB module, reassembled from its Ghidra listing, matched the real .efi byte for byte, which proved the disassembly was read correctly. Both stages are written from zero in C:

chikuma/bootrom/   the mask ROM
chikuma/onb/       all 40 modules of the NOR bootloader

C output cannot match Apple's compiler byte for byte, so the gates test behaviour instead. Each module has a host suite against the image's own bytes, QEMU integration payloads run against the device models, and the whole chain has to boot the original firmware. The boot chain, in C covers how it builds and what each gate checks.

The Firmware Volume goes through this tree's own parser and serialiser, chikuma/onb/tools/fv_bundler.py. It swaps each module's C-built PE image into the volume by GUID and writes the volume back out.

cd chikuma
make onb-full-c-fv       # every non-SecCore module as an independently emitted C PE image
make secureboot          # ... plus the bootrom, signed with the Chikuma CA
make secureboot-disk     # ... planted on a fresh copy of the disk image

Signing a Chikuma build

Chikuma's boot ROM carries its own root-of-trust hash in place of Apple's, so the whole X.509 chain can be Chikuma's. firmware/chikuma_ca is a self-contained CA, kept in its own git repository out of the main tree.

Certificate Key Notes
root RSA-2048 mirrors Apple's
intermediate RSA-1024
leaf RSA-1024 signs the image

All three use SHA-1 signatures and the 9-byte 01 FB 01 FB serials the ROM requires. bootstrap.sh regenerates the chain from the committed keys and never replaces a key, because a new leaf key would invalidate every image already signed.

Two build steps turn that chain into a bootable image:

cd firmware/chikuma_ca
# sign an arbitrary OSOS body (e.g. Apple's own decrypted osos-dec.dfu[0x800:])
make chikuma-osos-x509 OSOS_BODY=../extracted/osos-dec.dfu.body
# or pack and sign Chikuma's own build in one step: payload.elf -> OSOS two-view body -> signed container
make chikuma-osos-container            # CHIKUMA_ELF defaults to ../../chikuma/payload.elf

make_chikuma_osos.py packs the payload ELF into the two-view body the loader expects: body[0:0xAE5C] at 0x22000000 and body[0xAE5C:] at 0x08000000. It wraps that in the signed enc_type 3 container, leaf certificate first. The result goes into the osos slot of the !ATA directory (partition offset 0x4e07000), no longer than the 0xa06aa3 bytes Apple's entry declares, so it never runs into aupd.

The chain under QEMU

The chain runs complete on the emulated machine, from reset, with nothing of Apple's binaries left in the loaders.

Step State
boot ROM → SPI-NOR read → RSA/X.509 verify → AES decrypt → jump into the ONB works, from the C boot ROM
SEC → PEI (PreEfi) → DXE core → drivers → BDS works, from the C volume, all 40 modules
BDS finds osos, verifies it and jumps works, into Chikuma or into Apple's own unmodified RetailOS signed with the Chikuma CA

Starting the original firmware is the control. Apple's RetailOS boots through the chain unchanged.

The chain needs four pieces of the machine in the emulator:

  • SPI-NOR framing
  • SHA-1 padding, with the start-of-hash reset on the DATAIN-fed path
  • an NVRAM read
  • the 0x3d000000 modexp engine

The modexp engine

BDS's candidate loader calls back into the boot ROM's own dfu_header_verify with a hardcoded mode=2, the X.509/RSA branch. It does so whatever the container's enc_type says, so osos always goes through X.509 verification.

That verify runs on the block at 0x3d000000, modelled in qemu-ipod/devices/eccrsa.c. Despite the ecc_ names in the ROM, the block is a hardware modular-multiply accelerator, with no link to NAND. The RSA verify drives it through ecc_decode_page's square-and-multiply ladder. The ROM's own software mpi_exptmod and mpi_modinv have no callers at all.

The model implements three behaviours:

  • a per-command multiply ch[dest] = ch[a] * ch[b] mod N, with the destination in the descriptor's low byte
  • a command with config bit 1 that loads the identity to seed the accumulator
  • ecc_wait_channel's inline trigger, which copies the result into the channel the read returns.

With that, the model reproduces a real RSA-1024 verify of the intermediate by the root, against Apple's own 2048-bit root modulus.

The checks that are not crypto

Beyond the RSA-1024 PKCS#1 v1.5 signature on each certificate and the root-hash anchor, bootrom_verify_cert_chain checks two more things.

Check Rule
serial number exactly 9 bytes, starting 01 FB 01 FB, a hard compare. 01 FB 00 FB passes only when a chip-ID fuse bit is clear
signature hash SHA-1. The ROM's DigestInfo templates cover only MD5 and SHA-1, so a SHA-256 certificate fails the parse before any verification

Timing and the two timer lines

The ONB's 10 s and 30 s waits are Stall() busy-loops on a timer read. Under -icount shift=3 they run at a fifth of real time, so this chain wants --shift 7 --warp (running it in the emulator). Setting bit 0 of PMU register 0x0c ends the machine with qemu_system_shutdown_request, so the ONB's power-off path stops QEMU instead of spinning.

The hardware splits the timer interrupt in two: IRQ 8 for the 16-bit blocks and IRQ 7 for the 32-bit ones. ONB module 36 routes its own Timer F to 7. The machine splits the lines the same way, in devices/timer.c.