Flashing the Raspberry Pi Compute Module eMMC under Mac OS

Update on 13th November, 2014:
I tested it on my iMac (2009 early version) with Mac OS X Mavericks (10.9). According to some readers’ feedback, it may not work on some new Mac machines. I will investigate it and update accordingly.


The Raspberry Pi Compute Module has been released for a few months. Although the stand-alone compute module is not available yet, a lot of people have purchased the development kit, which includes a Raspberry Pi compute module. Different than other Raspberry Pi boards, the compute module has built-in 4GB eMMC, so you can directly install the OS on it. Yes, no more SD or TF card, yeah 🙂
If you have the development kit for Raspberry Pi compute module, you can follow this document on the Raspberry Pi foundation website to flash the eMMC on your compute module. However that document assumes you have another Linux machine (e.g. another Raspberry Pi) running as a host to write the raw OS image into the eMMC, what if you don’t have one? Well, if you have a machine that has Mac OS installed, you can still make it, and this tutorial is going to show you how.
First off, you need the development kit for Raspberry Pi compute module, otherwise you don’t need to read on 🙂
RPiCMDevKit
Mac OS is based on UNIX, so it is similar with Linux in some ways. You may already know that, the “dd” command is also available in Mac OS, so the solution is almost there! But wait, by lacking the “usbbootcode.bin” and “msd.bin” files in the eMMC, BCM2835 (the heart of Raspberry Pi) can not boot from USB, and your RPi CM will not be detected as a USB storage device, hence you don’t have the chance to “dd” it (yet).
The picture below shows that Mac OS knows there is a USB device, but could not initialize it as a USB storage device. Want to know why it is named BCM2708 instead of BCM2835? You can read this.
BCM2708

So the first task is to compile and run the “usbboot” tool on your Mac OS, which can detect your CM and write in those boot code files, so you can later treat it as a USB storage device.
You need to clone the project from github:

git clone --depth=1 https://github.com/raspberrypi/tools

If you try to compile it directly:

cd tools/usbboot
make
cc -g -o rpiboot main.c -lusb-1.0
main.c:1:10: fatal error: 'libusb-1.0/libusb.h' file not found
#include "libusb-1.0/libusb.h"
         ^
1 error generated.
make: *** [rpiboot] Error 1

It will fail because of the lack of the “libusb” library. In Mac OS you don’t have the “apt-get” command, so you need to install the library in a different way. You can download the latest source code of this library here, and then extract the *.tar.bz2 file to a directory. In the Terminal window, enter that directory and run “./configure” to configure the package for your system:

./configure

Then compile the package by typing “make”:

make

And then install it:

make install

After that you can continue compiling the “usbboot” tool:

cd tools/usbboot
make

This time you should not see any error and you will see the “rpiboot” file is generated.

ls
Makefile	main.c		rpiboot		usbbootcode.bin
Readme.md	msd.bin		rpiboot.dSYM

Now run the rpiboot tool, you may be asked to input your administrator password:

sudo ./rpiboot
Waiting for BCM2835 ...

If you have correctly set J4 jumper on I/O board to “enable”, connect the slave port on I/O board to your machine, and power your I/O board, the rpiboot tool should detect your CM and write the required boot code files into it:

Waiting for BCM2835 ...
Found serial = 0: writing file usbbootcode.bin
Successful
Waiting for BCM2835 ...
Found serial = 1: writing file msd.bin
Successful
Raspberry Pi is now a mass storage device, use lsblk to find it

If rpiboot still doesn’t recognize your BCM2835, the first thing to check is the USB port you connect your I/O board to. Booting from USB will need to draw certain current from your host USB port, so if the USB port could not provide that current, the booting will fail and thus rpiboot tool could not see your RPi CM. On my iMac, I noticed that connecting the I/O board to the USB port on Apple keyboard doesn’t work, while connecting to any USB port on the rear of iMac can work.
boot_bcm2835
If everything goes right, you will soon see a new device appear in your Finder, and you can treat it like a normal USB storage device. Because the eMMC has the boot code files now, you don’t need the help from rpiboot tool any more. Next time when you connect your I/O board to your PC, it can be directly recognized as a USB storage device.
If you check the system report again, you will see that Mac OS correctly recognize Raspberry Pi Compute Module now:
RPi_CM_Found
Although the rpiboot tool suggest to use “lsblk” command to find the new disk, it does not exist in Mac OS, however you can use “diskutil” to check the new device:

diskutil list

You should be able to see a device like this:

/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *3.9 GB     disk2
   1:             Windows_FAT_32 boot                    58.7 MB    disk2s1
   2:                      Linux                         3.8 GB     disk2s2

Now you know the new disk’s name, so you can “dd” it. Make sure you have unmounted all volumes on the new disk before using “dd”:

sudo diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
sudo dd if=raw_os_image_of_your_choice.img of=/dev/disk2 bs=32m

Please be patient as it will take some time. On my iMac it took 22 minutes to finish the writing. After it is done, the OS is installed into the eMMC and you can unplug the USB slave port and reboot your Raspberry Pi Compute Module. Congratulations!
RPi_CM_Running

See also

Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.