USB and disk mode¶
Plugged into a computer, the iPod is three things at once: a disk the Mac can mount, an audio and accessory device, and a source of its own date and identity. The running OS does all of it, and the bootloader can also start a separate, standalone disk mode. Chikuma reproduces both from Apple's code and checks them against Apple's answers on the same device.
The device stack¶
The USB controller is the Synopsys DWC2 OTG block. The emulator models its device half with a full data path. Chikuma's driver, recovered from the firmware's, brings the core up on the real iPod the way the original does.
Whether a computer is attached is a power question first. Of the three power sources the PMU reports, only one means "a data host", and only that one wakes the USB stack.
Two configurations¶
| Configuration | Original | Chikuma adds |
|---|---|---|
| 1, mass storage | one SCSI disk over bulk-only transport | in a development build, the HID and iAP 2 interfaces too |
| 2, audio and accessory | an audio streaming interface and an HID interface carrying iAP | an iAP 2 interface (OURS), which the original never had |
The audio interface has a zero-bandwidth default and an active alternate carrying 16-bit stereo 44.1 kHz PCM on an isochronous endpoint. The firmware assembles it at run time, so the image holds no fixed descriptor for it. iAP 2 is covered on Accessories.
Charge current¶
Connecting to a computer also sets the charge current. It is 100 mA after a bus reset, 500 mA once the host configures the device, and more if the host grants it with Apple's vendor request. Chikuma reproduces that selection, and Power has the charger.
Mass storage from the running OS¶
When a Mac mounts the iPod, the original does not reboot into a separate mode. The running OS lends the data disk to the host and takes it back later, through an ownership claim on the disk.
The hand-over¶
One arbiter holds the media, with an owner and a pending requester.
- The host's first command arrives, and the USB side asks for the disk.
- The system, which owns it, is asked to yield. It stops the player, closes its files, flushes the library's state and releases.
- Until then the disk answers becoming ready. Once the USB side owns it, the disk answers ready and the host mounts the volume.
Eject, a reconfiguration or a pulled cable runs it backwards. The USB side releases, the system claims the disk again, probes the volume afresh and reloads the library.
Chikuma has the hand-over in the same shape: one arbiter, the yield and the grant as callbacks, and the USB task doing the stopping and releasing.
While the host owns the disk¶
The disk-mode screen is built from the resource archive, as the original builds it. While the host reads, it shows Connected with "Use iTunes to eject" under turning arrows. While the host writes, it shows Synchronizing with "Please wait". The original's SCSI side raises a different event for a read and for a write, and that event picks the message.
The backlight stays on for the whole session, as on the original. The library is set aside, and after the eject the interface goes back to the main screen while the library reloads.
The hand-over in the emulator¶
The hand-over depends on the emulator restoring every audio DMA channel from a saved state. With one channel missing, the original waits for its sound engine to stop, and the disk answers becoming ready forever. With the channel restored, both firmwares get through.
What the Mac reads about the iPod¶
Beyond the disk, a Mac reads two kinds of identity over SCSI. Chikuma answers both the way Apple's firmware does.
| Source | Content |
|---|---|
| INQUIRY vital-product pages | the supported-pages list, the serial number, a device identifier, block limits giving the 4 KiB block size, and a set of vendor pages |
| SysInfoExtended plist | the document iTunes and Finder use to learn what the iPod is and what it can play. The device builds it and serves it in chunks through the vendor pages |
The plist builder is reproduced with its quirks: the serial's escaping, one key name spelled as the device spells it, and no newline after the closing tag.
Compared with Apple's disk mode¶
On the same development unit, the vital-product pages match byte for byte. The plist differs only in the keys Chikuma answers on its own, because the image gives no source for them:
| Key | Chikuma's answer |
|---|---|
| connected bus name | OURS |
| bus-power flags | OURS |
| corrupt-data-partition flag | OURS |
One more key differs on purpose, as it does on the original. The running OS reports that it is not in forced disk mode.
The clock record¶
Every time a Mac attaches, it sends the iPod the date and time in a 12-byte record, with a SCSI WRITE BUFFER. The original applies it the way its Set Date & Time screen does, and so does Chikuma. That is how an iPod that has been plugged in knows the time.
The disk-mode window¶
The bootloader can also start a standalone disk mode. It is a small image of its own, not a mode of the OS, and it starts when the reboot reason asks for disk mode.
It does not show the host the whole disk. It reads the partition table in the disk's first block, finds the first firmware-class partition, and shows the host everything after it as one disk. The capacity it reports is the total minus that base, so the firmware partition below the window is out of reach of ordinary reads and writes.
Chikuma's disk mode reproduces Apple's, with the same window. It lives in the disk's firmware partition, so flash is never written for it. The reproduced bootloader looks for it first and falls back to Apple's when it is absent.
Two differences remain. The windowed build refuses host writes for the moment, so it does not yet replace an iTunes or Finder sync. And Apple's disk mode only ends when the cable comes out, where Chikuma's also ends on a reboot command from the host.
Apple's vendor command family¶
Apple's disk mode answers a family of vendor SCSI commands under one opcode, 0xC6. Read from the
image:
| Sub-command | Effect |
|---|---|
0x90 |
loads a hash record sent by the host and resets a write cursor |
0x91 |
writes host data sequentially from that cursor straight into the firmware partition, on the raw drive. This is the restore path: a whole firmware partition, written linearly, not one image at a time |
0x94 |
"touches" the firmware. If the first block has no firmware partition, it builds a fresh partition table of its own and writes it |
0x92 |
always answers good |
0x95 |
carries a size in KiB |
| others in the range | answer good and do nothing |
0x94 rewrites the partition table
It looks like a harmless reboot request. On the development unit it replaced the partition table, and the Mac could no longer read the disk until the layout was restored. The hazard is listed on On the device.
Status¶
| State | Pieces |
|---|---|
| Reproduced | the two configurations, bulk-only mass storage with its sense format, host writes reaching the drive from the running OS, the hand-over of disk ownership and the disk-mode screen, the vital-product pages and the plist, the clock record, the charge-current selection, and the standalone disk mode with its window |
| OURS | the iAP 2 interface, the plist keys listed above, the bootloader trying Chikuma's disk mode before Apple's, leaving disk mode on a host command |
Behaviour not yet measured¶
After an eject, what the original does to the link is not known. Chikuma answers medium not present until the link resets. Whether the original's idle logic can still dim the backlight during a session is also open, and so is the repaint rate of the turning arrows. Host writes through the standalone disk mode are not there yet.