The restore, end to end¶
When iTunes restores an iPod Classic 6G with an empty disk, a blank NOR or both, five programs take turns on the device and two of them arrive over USB. Following them in order explains why disk mode lives in NOR, and why the firmware partition never shows up as a disk on the Mac.
ROM -> DFU -> WTF -> DFU -> second stage (NOR gets an ONB) -> ONB -> disk mode
-> firmware partition filled -> osos
Each step carries a tag for how it is known.
| Tag | Meaning |
|---|---|
| MEASURED | on hardware, in the emulator, or statically (the code read through, not run) |
| INFERRED | from code that has been read |
| OPEN | not established yet |
| Step | What runs | How it is known |
|---|---|---|
| Blank NOR | the boot ROM's DFU loop | MEASURED on hardware |
| The WTF | the first image the host sends | MEASURED |
| Second stage | aupd's recovery build, which writes the ONB | MEASURED statically |
| The fresh ONB | BDS, falling through to disk mode | MEASURED, in C |
| Disk mode | disk.bin, a USB mass storage device |
MEASURED on hardware |
| Filling the partition | vendor SCSI 0xc6 |
MEASURED statically, partly OPEN |
| Reboot | ONB, then osos |
MEASURED in the emulator |
What a blank device is missing¶
A restore fills two separate stores.
| Store | Holds | Size |
|---|---|---|
| NOR flash, 1 MiB | SysCfg, the ONB, and the flsh image directory (disk, diag, appl, lbat, bdsw, bdhw, chrg) |
ONB at offset 0x8000, 128 KiB |
| disk, firmware partition | osos (RetailOS), aupd, rsrc and others, in an image index |
100,663,296 bytes |
Two measurements give that partition size and they agree. The device's own info plist says
FWPartSize = 196608 in 512-byte units, and this project's built image uses 24576 blocks of 4096.
The disk's data partition is the HFS+ volume the user sees. The OS does not live there.
Blank NOR: the ROM's DFU loop¶
With nothing bootable in NOR, the mask ROM falls into its USB DFU loop.
cold boot ROM -> (GPIO picks the device) -> ONB from NOR at 0x22000000 -> RetailOS from disk
recovery ROM -> USB DFU -> WTF at 0x22000000 -> USB DFU -> whatever the host sends
The device enumerates as Apple 0x05ac / 0x1245, product string "iPod Recovery", measured on real
hardware. Two written sources, wInd3x's Nano3 entry and Rockbox's mks5lboot/ipoddfu.c, give
0x1223 for this family, and both are wrong for this device.
mac-installer/.../DeviceWatcher.swift carries the correction and its evidence.
The host sends the WTF¶
The ROM's DFU loop takes one image and jumps to it, exactly as it would jump to the ONB. That image is the WTF (the WTF, the recovery stage).
The WTF reads its boot cookie, brings up the clocks and SDRAM, and initialises the NOR-backed SysCfg.
It builds the device-info block from the tags. Then it runs a second DFU session, advertising
iPod Recovery, to receive the next image.
That second session is the ROM's own DFU code again. The WTF calls dfu_session_init and
dfu_wait_for_done through the ROM's exported table at 0x20000020, with its own load window
(0x08000000, up to 0xf80000 bytes). It patches idProduct to 0x1245 and pulses a USB soft
disconnect so the host enumerates it afresh. From the host, the two sessions look identical.
The WTF carries a NOR writer and never calls it¶
MEASURED, statically. The WTF holds a complete SPI-NOR driver, write side included.
firmware/extracted/wtf-decrypted.bin is 30,768 bytes.
| What | Where | Detail |
|---|---|---|
| SPI port-base table | file offset 0x1c3c |
0x3c300000, 0x3ce00000, 0x3d200000, byte for byte aupd's aupd_spi_port_base (0x08003694), ported as port_base[3] in chikuma/aupd/flash/spinor.zig |
| write opcodes | 0x5af8..0x5cfc |
EWSR 0x50, 4K erase 0x20, 64K erase 0xd8, AAI 0xad, beside WREN 0x06 and RDSR 0x05 |
EWSR, 64K erase and AAI together in one region form a SPI-NOR programming sequence, and small constants do not cluster that way by chance. The WTF could erase and program the NOR on its own.
It never does. Erase and program are reachable only
through the NOR device table at 0x220073bc, and inside the WTF only the open, close, query and read
wrappers use that table. On its own path the WTF reads SysCfg out of NOR and writes nothing back.
No other image in this tree references that table or its write functions either. So the ONB, which
lives at NOR offset 0x8000, has to arrive some other way.
The second stage writes the ONB¶
MEASURED, statically. The image iTunes sends into the WTF's session is
FIRMWARE.x1245.RELEASE.dfu, aupd's recovery build.
| link address | 0x08000800, where the WTF enters every image |
| code | 97% of its functions instruction-identical to aupd's |
| removed | the UI |
| added | the WTF's UART driver |
| kept | aupd's whole SPI-NOR write driver |
Its main is aupd's, call for call, without the drawing. It runs a version gate and an update
pre-check, then aupd's candidate loop. The loop's NOR-image branch copies the 0x1f800-byte ONB body
out of the candidate, verifies it and commits it to flash. Last, it sets the reboot reason to
"diskmode" and reboots.
That reason is what the restore turns on. The fresh ONB reads it and hands the disk to the host (disk mode), and the host then fills the firmware partition.
Chikuma's own recovery build of aupd reproduces this main. Loaded by Chikuma's WTF on the emulator, it
prints AUPD Start and AUPD End over the UART and leaves "diskmode" behind. Neither build has
been handed an ONB candidate there yet, so the flash write is read from the code and not watched.
aupd and the second stage are one NOR flasher built twice. aupd handles the in-field update (the ordinary update), where BDS can load it from a disk that already has content. The recovery build covers the case where it cannot, and comes over USB instead.
The fresh ONB, with nothing on disk¶
MEASURED, in C. The ROM loads the new ONB from NOR. Its end-of-boot decision is
onb_bds_boot_candidate_policy, ported branch for branch in chikuma/onb/02_Bds/policy.c. It tries
candidates in this order:
- status A == 7 ->
diag. Status B: 5 ->diag, 0x11 (ATA present) ->disk, 9 ->scan aupd, if its info word is zero: prep, mark handled, load and start- reason !=
"diskmode": ifdfupis absent andrsrcpresent ->osr3, elseosos - the disk path: if the ATA protocol locates,
disk_prep, thendiskwith mode 0x10 - nothing booted ->
bdhwscreen,Stall(30 s), display off
A blank disk has no osos and no rsrc, so step 3 finds nothing and control reaches step 4. disk
is a NOR flsh image (disk.bin, 213 KiB), so it runs even though the disk is empty. Disk mode lives
in NOR so it can run when the disk cannot.
The power source decides whether it gets that far.
IPOD_PWR_SRC |
What the policy does |
|---|---|
| 3, a data host present | "tried the disk candidate, DrawJpeg(bdhw), Stall(30 s)" |
| 2, charger only | never reaches the disk path, stops in the power-off loop at 3.9 s |
Disk mode over USB¶
MEASURED on real hardware. disk.bin brings up the DWC2 core and presents a USB Mass Storage
device. Its SCSI responder is the same code aupd carries without running it: disk_body.bin at
0x13194 and aupd-decrypted.bin at 0xfb30c hold the same 48 bytes, the INQUIRY identity table.
mac-companion/scsiprobe confirms it against a real device:
INQUIRY 00 80 00 00 33 00 00 00 "Apple " "iPod " "1.62"
CAPACITY last LBA 29255990, block size 4096, 119.83 GB
Every field that aupd_scsi_inquiry_standard (0x080fb0cc) writes matches. Removable 0x80 sits at
+1, additional length 0x33 at +4, the vendor at +8 and the product at +0x10.
The firmware partition is outside the exposed LBA space. The APM read off the device has exactly two
entries, the partition map and Apple_HFS from LBA 64 to the end. There is no Apple_MDFW, so disk
mode shows the host the data partition and nothing else.
The host fills the firmware partition¶
MEASURED, statically. READ(10) and WRITE(10) cannot reach the firmware partition. The
device's info plist, read over the vendor VPD range, says how the firmware goes in instead:
UpdateMethod 3
MaxFWBlocks 16
FWPartSize 196608
AutoRebootAfterFirmwareUpdate true
VolumeFormat HFSPLUS
CorruptDataPartition false
So the firmware goes through an update protocol, at most 16 blocks per operation, and the device
reboots itself at the end. The recovered dispatcher lists vendor SCSI opcode 0xc6 for this
(chikuma/aupd/usb/scsi.zig).
The 0xc6 sub-operations¶
Read one by one in Apple's NOR disk mode, three sub-operations make up the restore.
| Sub-op | What it does |
|---|---|
0xc6/0x90 |
takes a data phase, resets the write cursor to zero and marks the stream open |
0xc6/0x94 |
formats. Takes the firmware size from the CDB, writes a new partition table to block 0 (firmware partition at block 0x3f, a data partition after it), writes a fresh firmware header, and runs an initialisation at the data partition's start |
0xc6/0x91 |
the stream. n blocks of host data go to the raw drive at block cursor / block size + 0x3f, and the cursor advances by n × 4096 bytes |
The position never comes from the command, and the only bound is the size of the raw drive. The firmware partition fills linearly from its first block, as a whole-partition restore and not a per-image update. A fourth sub-operation answers a size in KiB.
0x94 on a real device
Issued on a real iPod, 0x94 rewrites block 0. The Mac can no longer read the disk until its
partition table is restored.
Whether the restore also formats the data partition is only partly answered. 0x94 writes at the
data partition's start, but the body of that initialisation is unread, so it may lay down a
filesystem or only clear a header. VolumeFormat = HFSPLUS and CorruptDataPartition show that the
device cares about the state of the data volume. The order above is the code's, and no host has been
watched sending it.
aupd's header goes through X.509¶
MEASURED, in C. onb_bds_load_and_start_image_candidate runs a header pre-check
(rom->Validate, kind 1) and, on success, rom->Finalize. In chikuma/onb/26_ROM/rom.c:319:
The 2 is hardcoded. It selects the X.509 chain and RSA signature branch of dfu_header_verify
(chikuma/bootrom/dfu.c), never the GID/UID-MAC branch (mode 1, no certificate) that the ROM's
cold-boot loader tries first for the ONB. Module 26's other entry point, its own RunDfu, hardcodes
the same 2.
So aupd, like every other disk candidate, passes only through the certificate path. That is why
chikuma_secure_boot.py only ever emits enc_type 3 containers.
The vendor VPD range¶
aupd_scsi_vpd_supported_pages (0x080fb57c) advertises pages 0x00, 0x80, 0x83, 0xb0, then all
of 0xc0..0xff. The device answers exactly that: 68 pages, page length 0x44.
| Page | Carries |
|---|---|
0x80 |
the serial |
0x83 |
the FireWire GUID |
0xc2.. |
the device-info plist, in 0xf8-byte chunks, as aupd_scsi_vpd_vendor and aupd_scsi_vpd_log_chunk page it |
These pages are read-only and safe, which is why they could be checked on a device. They give information and offer no path to the firmware partition.
Reboot into the OS¶
MEASURED, in the emulator. With the firmware partition populated, the ROM loads the ONB from NOR,
BDS's step 3 now finds osos, and RetailOS starts. qemu-ipod/run_secure_boot.sh runs that exact
chain, with a signed osos planted at iPod_Firmware+0x4e07000.
aupd fits in here too. When the firmware partition carries an aupd whose index entry is still type
0 ("update pending"), BDS runs it before osos. It updates the NOR, marks the entry handled and
reboots. That in-field ONB update is reproduced in chikuma/aupd/main.zig.
The ordinary update¶
A normal firmware update never goes near DFU, because RetailOS exposes the same SCSI vendor interface itself. The 48-byte INQUIRY identity table appears in all three images:
osos-dec.dfu 0x0e6bd0 RetailOS
disk_body.bin 0x013194 the NOR disk-mode image
aupd-decrypted.bin 0x0fb30c aupd
They match byte for byte, "Apple " / "iPod ", and differ only in the pointer to the
revision string. RetailOS drives the responder from usb_diskmode_task (0x221320d8). Beneath it sit
usb_diskmode_lun_construct, diskmode_lun_block_size, diskmode_lun_last_lba and the
usb_diskmode_session_* group, all named in the Ghidra project.
| # | Step | How it is known |
|---|---|---|
| 1 | RetailOS is running and iTunes connects. RetailOS presents mass storage plus the vendor SCSI extension, with the same 0xc0..0xff VPD range and vendor opcodes as the restore |
INFERRED |
| 2 | iTunes writes the new osos, and an aupd, into the firmware partition over the vendor protocol, since WRITE(10) cannot reach it |
INFERRED |
| 3 | the aupd index entry stays at type 0, "update pending" |
INFERRED |
| 4 | reboot. BDS reaches step 2 of its candidate order, finds aupd with a zero info word, runs onb_bds_aupd_prep, marks the entry handled with SetInfo and starts it, all before it looks for osos |
MEASURED |
| 5 | aupd updates the NOR: erase 0x08000..0x28000, AAI-program the ONB region, reboot |
MEASURED |
| 6 | the ROM loads the new ONB, BDS falls through to osos, and the new RetailOS starts |
MEASURED |
Steps 4 to 6 run in the emulator with qemu-ipod/run_secure_boot.sh --apple-aupd (Apple's own body)
and --aupd (Chikuma's). prepare_sb_disk.py plants the candidate as step 3 describes, and its own
output line says "aupd left type 0 (update pending) - BDS will load it before osos". Chikuma's aupd
completes the cycle: it draws, programs the NOR, reboots, and the machine comes back up into the OS.
Steps 1 to 3 rest on two facts. The responder is present in RetailOS, and the firmware partition is not LBA-addressable. Nobody has watched iTunes perform the write.
Why aupd carries a USB stack it never runs¶
aupd's MSC code is the same shared library that RetailOS and disk.bin link against. Hooking a live
--apple-aupd update shows aupd_usb_port_sense firing twice, the battery gate asking about power,
and aupd_msc_register never firing at all. aupd only flashes the NOR, and another stage exposes the
device to the host.
What the verifiers check¶
MEASURED. The ROM and aupd verify headers the same way, and neither uses a public-key signature on its fast path.
The ROM, which the WTF calls back into¶
dfu_verify_signature (0x200005dc) is ported byte for byte in chikuma/bootrom/dfu.c:
SHA-1 over the first 0x40 bytes of the header
AES "job mode 7" over the 16-byte digest, key source = mode (1 or 2), zero IV
compare those 16 bytes against header + 0x40
then require the magic "8702"
That is a device-keyed MAC. The AES key is the hardware GID or UID, chosen by mode, so only this
family of SoC can produce a valid header, and no public key is involved.
Two more details matter. The function refuses outright when boot_config_pins_read() == 1, so a
hardware strap makes this path fail and pushes the caller to the other one. And when it fails with
enc_type 3 or 4, boot.c falls through to dfu_header_verify (0x200006dc), the X.509 certificate
path.
The ROM therefore supports two verification families, a GID-MAC fast path and a certificate chain,
chosen by enc_type and a strap. This project's own CA signs enc_type 3 containers, which is why
run_secure_boot.sh boots images Apple never signed.
aupd¶
aupd_verify_digest_mode2 (0x08009d0c) tail-calls aupd_verify_digest_dispatch (0x08009d60) with
selector 2. The dispatch offers the same two families.
| Mode | Check |
|---|---|
| 1, 2 | aupd_digest over the 0x40-byte header, then aupd_aes_job_run over the 16-byte result, the same GID-MAC as the ROM |
| 3, 4 | the certificate path, with signature and certificate offsets laid out at +0x10, +0x14 and +0x18 before checking |
| other | answers 9 |
The selector indexes aupd_verify_mode_table at 0x08011ee0, 16 bytes per row, one row per SoC:
| Index | Header size | Magic | Version |
|---|---|---|---|
| 0 | 0x800 | 8441 |
1.0 |
| 1 | 0x800 | 8701 |
1.0 |
| 2 | 0x800 | 8702 |
1.0 |
| 3 | 0x800 | 8442 |
1.0 |
| 4 | 0x600 | 8720 |
2.0 |
The table has five rows. What looks like a sixth is the reboot-reason table next to it:
0x08011ee0 + 5*16 is 0x08011f30, which holds "--------" / "diskmode".
Index 2 is this device, with magic 8702, a 0x800 header and version 1.0, the im3 container shape
the rest of this project works with. aupd is built for the whole ARM iPod range and picks its row at
runtime. The same reason explains the USB stack it never runs.
Not yet watched¶
The second stage's NOR write is read from the code for the moment. Handing Chikuma's recovery build a payload with an ONB candidate on the emulator would show the write happen.
The other open point is the 0xc6 sequence. It is not known yet what 0x94's initialisation does to the
data partition, or how a host really orders the commands. Capturing the vendor CDBs while iTunes or
Finder restores a device would settle both, and would move steps 1 to 3 of the ordinary update from
INFERRED to MEASURED.