Installing Rockbox on the iPod Video without using iTunes

– updated on

All rock, no blobs

Installing the free Rockbox firmware on an iPod is very easy, the graphical installer can do that with just a few clicks. It does however require a working disk in the iPod and the disk must have initially been setup using iTunes. Today we are going to look into how to install Rockbox 'by hand' on a fresh disk, without using any proprietary software whatsoever.

It all started when I noticed that the disk in my iPod Video was about to die and I ordered an iFlash-CF that would allow me to use a CompactFlash card instead of a hard disk in the iPod. After installing the adapter and the card, I realized that the iPod was unable to boot from the card and needed to initialize it using iTunes. Since I don't want iTunes installed on my machine (not to mention Windows) I wanted to find a better way to initialize a CompactFlash card for an iPod.

Note: In this article `/dev/sdX` is my iPod and `/tmp/ipod` is the directory where I compile things. You can easily adjust these values to match your own setup:

/dev/

This should update the article accorindly.

Rockbox?

For those who don't know, Rockbox is a free operating system for audio players. It can be installed on countless different devices and offers all kinds of features that far exceed the devices' original functionality. Among many other things, Rockbox allows these devices to play Ogg Vorbis and losslessly compressed FLAC files. Also, devices such as the iPod usually require proprietary software just to copy your music to the player – with Rockbox, the iPod can be used as a regular mass storage device, files can easily be copied with your favourite file manager.

What needs to be done

This is how an iPod's storage is organized:

Assuming our flash card is currently empty, we need to take care of three things:

• The master boot record (MBR) with the partition table
• The firmware partition
• The data partition

The tools to create an MBR are most likely already installed on your machine, the same thing goes for the data partition. We will however need special software to create the data on the firmware partition as well as the `.rockbox` directory in the data partition. During the next couple of steps we are going to compile the required tools and use them to build an image for the iPod.

Compiling Rockbox

Since we don't want to use the simple automatic installer, we will first need to acquire the source core. We will be using /tmp/ipod to compile it – feel free to change this path in the article options.

```\$ mkdir -p /tmp/ipod ; cd /tmp/ipod
\$ git clone git://git.rockbox.org/rockbox
\$ cd rockbox
```

Now we have our own local copy of Rockbox' source code and can start compiling it.

Cross compiler

We need a cross compiler to compile Rockbox for the iPod's ARM architecture. Luckily, Rockbox includes one of those. We start by defining a couple of paths for our files:

```\$ export RBDEV_DOWNLOAD=/tmp/ipod/archives
\$ export RBDEV_PREFIX=/tmp/ipod/target
\$ export RBDEV_BUILD=/tmp/ipod/build
```

Then we run the script to compile the cross compiler:

```\$ cd tools/
\$ ./rockboxdev.sh
Install prefix     : /tmp/ipod/target  (set RBDEV_PREFIX or use --prefix= to change)
Build dir          : /tmp/ipod/build (set RBDEV_BUILD or use --builddir= to change)
Make options       :  (set MAKEFLAGS or use --makeflags= to change)
Restart step       :  (set RBDEV_RESTART or use --restart= to change)
Target arch        :  (set RBDEV_TARGET or use --target to change)
Select target arch:
s   - sh       (Archos models)
m   - m68k     (iriver h1x0/h3x0, iaudio m3/m5/x5 and mpio hd200)
a   - arm      (ipods, iriver H10, Sansa, D2, Gigabeat, etc)
i   - mips     (Jz47xx and ATJ-based players)
r   - arm-app  (Samsung ypr0)
x   - arm-linux  (Generic Linux ARM: Samsung ypr0, Linux-based Sony NWZ)
y   - mips-linux  (Generic Linux MIPS: AGPTek Rocker)
separate multiple targets with spaces
(Example: "s m a" will build sh, m68k and arm)```

We choose a (arm) for the architecture and wait for things to be compiled; on my rusty old Core 2 Duo that takes about 15 minutes.

Then we add the cross compiler to our path in order for the build system to find it:

`\$ export PATH=\$PATH:/tmp/ipod/target/bin/`

That's it, now we are ready to compile Rockbox itself.

Rockbox itself

Let's use our cross compiler to build Rockbox. First we will need to create an output directory:

```\$ cd /tmp/ipod/rockbox
\$ mkdir -p build ; cd build```

Then we configure the build system:

```\$ ../tools/configure
Using temporary directory /tmp
Enter target platform:
==Archos==               ==iriver==             ==Apple iPod==
0) Player/Studio        10) H120/H140          20) Color/Photo
1) Recorder             11) H320/H340          21) Nano 1G
2) FM Recorder          12) iHP-100/110/115    22) Video
3) Recorder v2          13) iFP-790            23) 3G
[…]```

For the iPod Video, we choose option 22 ('Video' under 'Apple iPod').

```Platform set to ipodvideo
Build (N)ormal, (A)dvanced, (S)imulator, (B)ootloader, (C)heckWPS, (D)atabase tool, (W)arble codec tool: (Defaults to N)```

Type N for a 'normal' build.

```Normal build selected
Using source code root directory: /tmp/ipod/rockbox
Using arm-elf-eabi-gcc 4.4.4 (404)
Using arm-elf-eabi-ld 2.20.1.20100303
Detected make GNU Make 4.2.1
Automatically selected arch: arm (ver 4)
Created Makefile```

Now the build system is ready and we can start compiling:

`\$ make`

That's going to take a while, about 12 minutes on my machine. When it's done, we can create a tarball with the required Rockbox files:

`\$ make tar`

This should only take a few seconds. Afterwards we can build a few extra tools for iPod that we will be needing later:

```\$ make -C ../rbutil/ipodpatcher/
[…]
\$ make -C ../tools/ ipod_fw```

That's it, now we have all the tools we need and can get started on our images.

Which iPod Video?

Before we can setup the flash card, we need to figure out one small but important detail: which exact type of iPod are we using? There are (at least) two different editions of the iPod Video that look exactly the same on the outside. Both carry the model number 'A1136' but their storage setup differs in an important detail: one of them uses 512 bytes per sector, the other one uses 2048 bytes per sector. The installation procedure differs a bit for the different models.

We can use the tools that ship with Rockbox to figure out how large our iPod's logical sectors are; the command needs to be run as `root`:

Models with 512 bytes per Sector

```# ../rbutil/ipodpatcher/ipodpatcher -l
[…]

[INFO] Scanning disk devices...
[INFO] Read XML info (4 bytes)
[INFO] Ipod found - Photo/Color ("winpod") - /dev/sdc
[INFO] Reading partition table from /dev/sdc
[INFO] Sector size is 512 bytes
[…]```

Models with 2048 bytes per Sector

```\$ ../rbutil/ipodpatcher/ipodpatcher -l
[…]

[INFO] Scanning disk devices...
[INFO] Read XML info (9692 bytes)
[INFO] Ipod found - Photo/Color ("winpod") - /dev/sdc
[INFO] Reading partition table from /dev/sdc
[INFO] Sector size is 2048 bytes
[…]```

There it is, the command will either say 'Sector size is 512 bytes', or 'Sector size is 2048 bytes'; let's remember that information. If the iPod's current disk doesn't work at all (or if the iPod doesn't have a disk) the command will fail and we can't figure out which sector size to use. In this case, we will just have to try both – either the instructions for 512 bytes or those for 2048 bytes should work.

The memory card

Now we can start preparing the memory card by setting up a partition table. Install the card in the iPod and hold the SELECT and PLAY buttons while turning it on. This way, the iPod will start in 'Disk Mode' which allows us to access the memory card directly. Then we connect the iPod to our PC.

Partitions

If we use iTunes to initialize the memory card, it creates two partitions: a firmware partition for the operating system and all kinds of Apple stuff, and a data partition for the music. It allocates 80 MB for the first partition – let's be a little less wasteful.

The only thing that really needs to be on this partition is the image we just built, so in order to know how big our partition needs to be, we can just look at the image's size:

```\$ stat -c %s rockbox.ipod
807828```

In this case, my firmware image is 807828 bytes. Even if we add a couple of bytes for the header, the directory and possibly a few extra images, 2 MB (2097152 Bytes) should be more than enough. With a sector size of 512 bytes that means we need at least $2097152/512=4096$ sectors on the memory card.

The MBR itself also needs a bit of space, thus the iPod expects the first partition to start at sector 63. I use `sfdisk` to create the partitions because it's easily scriptable.

The next step depends on our iPod's sector size:

iPods with 512 bytes per sector

• The iPod expects its MBR to start at sector 63, our first partition is going to start there (`start=63`).
• With 512 bytes per sector, we need a grand total of 2097152 / 512 = 4096 sectors for the firmware partition (`size=4096`).
• The data partition starts after that, i.e. at sector 63 + 4096 = 4159 (`start=4159`).

This is what the script for `sfdisk` looks like:

``````label: dos
unit: sectors
start=63, size=4096, type=0
start=4159, type=b``````

iPods with 2048 Bytes per sector

• The iPod expects its MBR to start at sector 63, our first partition is going to start there (`start=63`).
• With 2048 bytes per sector, we need a grand total of 2097152 / 2048 = 1024 sectors for the firmware partition (`size=1024`).
• The data partition starts after that, i.e. at sector 63 + 1024 = 1087 (`start=1087`).

This is what the script for `sfdisk` looks like:

``````label: dos
unit: sectors
start=63, size=1024, type=0
start=1087, type=b``````

Save that script as `/tmp/ipod.script` and run it with `sfdisk` (as root):

```# sfdisk /dev/sdX < /tmp/ipod.script
Checking that no-one is using this disk right now ... OK
[…]
The partition table has been altered.
Syncing disks.
```

This should create two partitions on the card. Let's have a look at our new partition table:

iPods with 512 bytes per sector

```\$ sfdisk -l /dev/sdX
[…]
Device     Boot Start     End Sectors   Size Id Type
/dev/sdX1          63     4158     4096     2M  0 Empty
/dev/sdX2        4159 30668799 30664641  14.6G  b W95 FAT32```

iPods with 2048 Bytes per sector

```\$ sfdisk -l /dev/sdX
[…]
Device     Boot Start     End Sectors  Size Id Type
/dev/sdX1          63    1086    1024    2M  0 Empty
/dev/sdX2        1087 7896575 7895489 15.1G  b W95 FAT32```

Firmware

The iPod expects to find its operating system in the firmware partition. In addition to the image we already built, we will need to add a special header and a directory that tells the iPod where to find the system image when it powers on.

As the illustration shows, the firmware partition can contain multiple images. Rockbox supports at least four different combinations of images, each with its own pros and cons. Since we do not ever want to run any kind of Apple-provided firmware, we are going to use option 4 ('OSOS contains only Rockbox'); unfortunately, the iPod Video doesn't support that, we need to another pseudo image to the firmware:

The rockbox image is the one we have already built, it's called `rockbox.bin` and is currently sitting in the `build` directory. The Rockbox tools can create the pseudo image for us. First we will need to build a firmware image for the `ipod5g`:

`\$ ../tools/scramble -ipod5g rockbox.bin temp.img`

Unfortunately there are a few zero bytes missing at the end of the image. This wouldn't matter if we flashed the image directly to the iPod, but as we are going to do further unspeakable things to it, we need to add a bit of padding:

`\$ dd if=/dev/zero of=temp.img oflag=append conv=notrunc bs=1024 count=1`

In theory, we should be able to just flash this image to the iPod and be done with it. Unfortunately, `scramble` can currently only create images for iPods with 512 bytes per sector (and even those aren't entirely correct), so we are just going to extract the empty partition from this image and throw the rest away. We cannot choose our own file name, it's hard-wired in the `ipod_fw` utility:

`\$ ../tools/ipod_fw -o apple_sw_5g_rcsc.bin -e 1 temp.img`

Now we have both images, the Rockbox image in `rockbox.bin` and an extra, empty image just to please our iPod in `apple_sw_5g_rcsc.bin`. We can use these to create our image for the firmware partition:

iPods with 512 bytes per sector

```\$ ../tools/ipod_fw -g 5g -o firmware.bin -l rockbox.bin -n -r 0xb000
Generating firmware image compatible with iPod video```

iPods with 2048 Bytes per sector

```\$ ../tools/ipod_fw -s 2048 -g 5g -o firmware.bin -l rockbox.bin -n -r 0xb000
Generating firmware image compatible with iPod video```

And finally write the image (as root) to the first partition:

`# dd if=firmware.bin of=/dev/sdX1 bs=512`

Now our operating system should be ready.

Data

Now we create an `FAT32` file system on the second partition to hold our music. Again, we do this as root:

iPods with 512 bytes per sector

`# mkfs.vfat -F 32 /dev/sdX2`

iPods with 2048 Bytes per sector

`# mkfs.vfat -F 32 /dev/sdX2 -S 2048`

Then we extract the tarball with our Rockbox files:

```# mount /dev/sdX2 /mnt/ipod
# tar --no-same-owner -C /mnt/ipod/ -xf rockbox.tar
# umount /mnt/ipod```

... and done. That's it. The next time we restart the iPod, we should see Rockbox.

Unless all you want to do is play Sokoban, now is the time to copy some music to the iPod. While mine is greedily feeding on my music collection, I am ready to move on to the next little project – as I look at these picture, it seems to be time to shop for a new LCD.