Full Compute Module 4 (Raspberry Pi) Setup / Imaging Guide

Raspberry Pi Compute Module 4 mounted in IO Board
Raspberry Pi Compute Module 4 mounted in IO Board

The Raspberry Pi Compute Module 4 is primarily meant for embedded projects and didn’t catch my interest at first. That was until people started absolutely smashing previous records on my Pi storage benchmarking site pibenchmarks.com.

Upon further investigation it turns out that people are breaking these records using the Compute Module 4 since it allows running a NVMe drive through PCI express instead of having to use a USB adapter (the current bottleneck in other Pis).

Wanting to investigate these new capabilities for myself I got a hold of some gear and wanted to write a setup and configuration guide on everything you need for a full CM4 (Compute Module 4) setup and how to get it imaged and configured. Let’s get started!

Hardware Prerequisites

The Compute Module 4 is a bit more in depth to work with than other models of the Raspberry Pi and has some prerequisites you need first to work with them. Once you have them it’s very easy to work with multiple compute modules with varying capabilities (some will have no WiFi, some will have no eMMC, some won’t have either). The ones that have WiFi + eMMC are the hardest to find and can get expensive (as in over $100, unheard of for a Pi) if you also get a high memory option like a 4GB or 8GB Compute Module 4.

The Compute Module 4 by the Raspberry Pi Foundation is a single-board computer (SBC) that is meant to be used in embedded devices. It has many new capabilities that have not been seen on other Pis before such as a built in eMMC module (optional) and has PCI express capabilities when used with the IO board.

Links: AliExpress.com*, Amazon.ae*, Amazon.ca*, Amazon.com*, Amazon.com.au*, Amazon.com.mx*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.in*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.sa*, Amazon.se*, Amazon.sg*

The “Raspberry Pi Compute Module 4 IO Board” is the most important one:

This is essentially the “motherboard” of the compute module. This IO breakout board lets us work with the compute module and get the ports we need to interface with it. This includes a SD card slot for models that don’t have eMMC, a PCI express slot (very exciting), 2 USB ports and more.

Links: AliExpress.com*, Amazon.ae*, Amazon.ca*, Amazon.com*, Amazon.com.au*, Amazon.com.mx*, Amazon.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.in*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.sa*, Amazon.se*, Amazon.sg*

There are also smaller and more purpose built boards (IO and otherwise) for the Compute Module 4 available but this is the one meant for development. The Compute Module 4 snaps into the IO board and becomes a part of it. Here’s what it looks like removed:

Compute Module 4 removed from IO Board
Compute Module 4 removed from IO Board

You will also need a power adapter. If you want to work with powerful NVMe drives or other power hungry PCI express technologies then I strongly recommend getting a full 12V DC adapter like this:

Delivers a full 12V DC to the IO board so that there’s enough power to run very powerful NVMe drives / accessories

Links: AliExpress.com*, Amazon.ae*, Amazon.ca*, Amazon.com*, Amazon.com.au*, Amazon.com.mx*, Amazon.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.in*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.sa*, Amazon.se*, Amazon.sg*

Here are the minimal power requirements. This power adapter will not give you much extra room for NVMe drives but the more power efficient ones will run from it. Highly recommend the bigger option.

A generic 5V 3A power adapter designed to be in the safe range for the Raspberry Pi 3 / 4 / routers / USB hubs / other small electronics. Comes with different tips to fit different connections but the default connection (no tip) fits the IO board perfectly.

Links: Amazon.ca*, Amazon.com*, Amazon.com.mx*, Amazon.sg*

You will need a data-transfer capable micro-USB cable to connect the IO board to your computer. Many of these are “charging only” cables since most things that use the data transfer use newer USB specs. Old cell phone cables are great bets here or you may have to try from a few cables you have. Worst case scenario here is one:

You will need jumpers. It can be the bridge style jumpers (often can be found on old motherboards, used for CMOS reset and the like) that are meant to jump two side by side or adjacent pins or you can use a breadboard female to female style jumper like this:

The board does not come with a CR2032 battery unfortunately. These are pretty easy to find though as they are the same type of battery that will be in any old motherboard (the round silver CMOS backup battery). They’re also widely available:

Imaging Compute Module 4 eMMC

To image the Compute Module 4’s eMMC storage we will need to put the Compute Module 4 into “mass storage mode” by setting the J2 jumper like I have in my picture at the very top of the article (I have a wired jumper but normal jumpers that just bridge the J2 pin with the pin directly below it will work fine as well).

There’s one more step though before it will show up as a mass storage device. We need to get the rpiboot utility. Here’s what the utility will allow us to do:

Usage: rpiboot
then contain a initramfs to boot through to linux kernel

To flash the default bootloader EEPROM image on Compute Module 4 run
rpiboot -d recovery

For more information about the bootloader EEPROM please see:
https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md

rpiboot                  : Boot the device into mass storage device
rpiboot -d [directory]   : Boot the device using the boot files in 'directory'
Further options:
        -l               : Loop forever
        -o               : Use files from overlay subdirectory if they exist (when using a custom directory)
                           USB Path (1-1.3.2 for example) is shown in verbose mode.
                           (bootcode.bin is always preloaded-bash: Usage:: command not found
 from the base directory)
        -m delay         : Microseconds delay between checking for new devices (default 500)
        -v               : Verbose
        -s               : Signed using bootsig.bin
        -0/1/2/3/4/5/6   : Only look for CMs attached to USB port number 0-6
        -h               : This help

To get the utility follow the instructions for your OS below.

Instructions (Windows)

For Windows we need to download and install the following:

Now you should have a new “Raspberry Pi” folder in your start menu that contains both the new usbboot utility and the Raspberry Pi imager utility like this:

"Raspberry Pi" Start Menu Folder with Right Click -> Run as administrator on rpiboot
“Raspberry Pi” Start Menu Folder with Right Click -> Run as administrator on rpiboot

Open the “rpiboot” shortcut from the new “Raspberry Pi” start menu folder by right clicking and choosing “Run as administrator” from the “More” menu (like the above screenshot) and it should open a black console window like this:

rpiboot utility
rpiboot utility

If you’ve set your jumper correctly for mass storage mode go ahead and connect the IO board’s micro-USB port (J19) to your PC and connect power to the IO board. You should see the following:

rpiboot utility after detecting CM4 in mass storage mode
rpiboot utility after detecting CM4 in mass storage mode

The window will disappear at this point and Windows will see the CM4’s onboard eMMC as a new mass storage device! Now open the Raspberry Pi Imager utility from the “Raspberry Pi” start menu folder. The CM4 will show up as a drive available to be imaged like this:

Compute Module 4 mounted in USB Mass Storage Mode within Raspberry Pi Imager
Compute Module 4 mounted in USB Mass Storage Mode within Raspberry Pi Imager

If your device wasn’t detected when you plugged in the power double check the following things:

  • Try running it several times as sometimes the boot process seems to get “stuck” and then removing power from the IO board and starting the process over it will work the next time
  • Try running as “Administrator” by going to the rpiboot shortcut in the “Raspberry Pi” start menu folder and right clicking on the shortcut and choosing More -> Run as Administrator
  • You set the jumper located at “Fit jumper to disable eMMC boot” J2 (jumped with the pin directly below it)
  • Check micro-USB cable type. Many of these cables are “charging only” and you need a micro-USB cable that is capable of data transfer. Ones from old cell phones are a great bet for this. Try some different cables if you aren’t sure if the one you are using has data transfer capabilities
  • Check that the CM4 model is “snapped” into the board on both sides securely
  • Make sure your model of CM4 actually has the eMMC (not all models do)

Instructions (Linux)

First install git, libusb, and make which are prerequisites:

sudo apt install git libusb-1.0-0-dev build-essential

Now clone the official Raspberry Pi usbboot utility’s repository and build the tool:

git clone --depth=1 https://github.com/raspberrypi/usbboot
cd usbboot
make
ls

You should now see the rpiboot utility in your current directory. You can install it system-wide with:

sudo make install

Whether you installed the utility system-wide or not it can now be used from the usbboot directory like this:

./rpiboot

If the Pi is connected and the jumper to disable eMMC booting is disabled (like in the picture at the top of this article) you should see the following output:

pi@pi:~/usbboot $ ./rpiboot
Waiting for BCM2835/6/7/2711...
Loading embedded: bootcode4.bin
Sending bootcode.bin
Successful read 4 bytes
Waiting for BCM2835/6/7/2711...
Loading embedded: bootcode4.bin
Second stage boot server
Loading embedded: start4.elf
File read: start4.elf
Second stage boot server done

We can verify that the device was mounted with:

ls /dev | grep "sd"

If you don’t have any other storage devices connected to the Pi this will usually be sda. If you do have other drives it will appear as a new entry like sdb, sdc, etc.

If you did not get the above output / your device wasn’t detected check the following:

  • Try running it several times as sometimes the boot process seems to get “stuck” and then removing power from the IO board and starting the process over it will work the next time
  • Try running as sudo (sudo ./rpiboot) to rule out anything like restrictive USB permissions for regular users and other configuration/environment restrictions
  • Check that the CM4 model is “snapped” into the board on both sides securely
  • Check micro-USB cable type. Many of these cables are “charging only” and you need a micro-USB cable that is capable of data transfer. Ones from old cell phones are a great bet for this. Try some different cables if you aren’t sure if the one you are using has data transfer capabilities
  • Make sure your model of CM4 actually has the eMMC (not all models do)

Once you’ve determined the drive is mounted you can use the Raspberry Pi imager to image the device (if your distro has a GUI).

You may also directly image the eMMC using dd on the CLI like this:

sudo dd if=raw_os_image_of_your_choice.img of=/dev/sdX bs=4MiB

After imaging is complete disconnect and reconnect the Pi so that the new partition table is read. You can now mount the partitions with:

cd /mnt
sudo mkdir boot
sudo mkdir root
sudo mount /dev/sdX1 /mnt/boot
sudo mount /dev/sdX2 /mnt/root

The first partition is the “boot” volume where config.txt and other files used during the boot process will be and the second partition is the “root” partition that contains the system and it’s files. You are now ready to configure the Compute Module 4!

Compute Module 4 Configuration

Now that you’ve finished imaging the module let’s make a few changes to make it more useful. Reconnect the Compute Module 4 to your computer using the USB cable (don’t remove the jumper from J2 disabling eMMC boot yet). Now that it is imaged you should see the “boot” volume where we can make some configuration changes.

Enable USB Ports

When mounted in the IO board the USB ports will not function without making a change to config.txt and adding an overlay.

Add the following line to config.txt:

dtoverlay=dwc2,dr_mode=host

After adding this line the two USB ports (as well as the “External USB” header) will function the next time the CM4 boots.

Enable SSH

It’s very useful to have SSH enabled when working with the Compute Module 4. It is enabled simply by creating an empty file named:

ssh

in the root folder of the “boot” volume (the top-most folder of the drive where start4x.elf, fixup.dat and those files are located).

Preconfigure WiFi / Wireless

You can also preconfigure the Compute Module 4 (and any Pi) by creating wpa-supplicant.conf at the base of the “boot” volume like we did with “ssh” file.

Create a new file named wpa-supplicant.conf that contains the following:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=US
update_config=1

network={
 ssid="YourNetwork"
 psk="YourPassword"
}

When this file is created in the base of the “boot” volume it will automatically be applied to the Pi upon the next startup. Make sure to adjust your country=US line to your own country as this can impact what channels and functionality are available from your WiFi card!

Update Firmware

If you try to update the CM4’s firmware with the rpi-eeprom-update tool you will get the following message:

pi@raspberrypi:~ $ sudo rpi-eeprom-update
rpi-eeprom-update is not enabled by default on CM4. Run with -h for more information.

This is disabled by default because an invalid recovery.bin / if power is lost during an update it can cause you to have to restore the firmware using the rpiboot utility since the Pi will not be able to boot and you can’t remove the built in eMMC module like you can with a SD card.

We need to use the rpiboot utility to update the firmware. I will use the latest firmware at time of writing but check for the latest firmware at: https://github.com/raspberrypi/rpi-eeprom/tree/master/firmware/stable (if there is a newer one replace the pieeprom-2021-07-06.bin in the curl command below with the newer version file name).

Linux Firmware Update Instructions

This is meant to be done on your same PC we imaged the Pi with and not the Pi itself (unless you have Windows, in which case you will need to do these instructions on the Pi and copy the resulting “recovery” folder to Windows, see “Windows Firmware Update” section for more info).

cd ~/usbboot/recovery
rm -f pieeprom.original.bin
curl -L -o pieeprom.original.bin https://github.com/raspberrypi/rpi-eeprom/raw/master/firmware/stable/pieeprom-2021-07-06.bin
./update-pieeprom.sh
cd ..
./rpiboot -d recovery

(Optional) If you want to modify the bootloader’s config such as which device is the primary boot device as well as other bootloader parameters you can actually do so using this same process by editing boot.conf in the recovery folder like this:

cd ~/usbboot/recovery
nano boot.conf
./update-pieeprom.sh

Next make sure your Compute Module 4 IO board’s “disable MMC boot” jumper J2 is bridged with the lower pin to disable eMMC boot. Now connect the power:

pi@pi:~/usbboot $ ./rpiboot -d recovery
Loading: recovery/bootcode4.bin
Waiting for BCM2835/6/7/2711...
Loading: recovery/bootcode4.bin
Sending bootcode.bin
Successful read 4 bytes
Waiting for BCM2835/6/7/2711...
Loading: recovery/bootcode4.bin
Second stage boot server
Loading: recovery/config.txt
File read: config.txt
Loading: recovery/pieeprom.bin
Loading: recovery/pieeprom.bin
Loading: recovery/pieeprom.sig
File read: pieeprom.sig
Loading: recovery/pieeprom.bin
File read: pieeprom.bin
Second stage boot server done

That is it! It’s quite a pain, but it’s because the compute modules are designed to be updated once at deployment and shipped with a stock image. They aren’t meant to be updated in the field like regular Pis (at least the Pi’s core firmware) but they can still be updated using this process. After removing the “disable eMMC boot” jumper and rebooting the Pi the firmware will be updated!

You can verify this once you boot the Compute Module 4 by running rpi-eeprom-update again which should now look like this:

sudo CM4_ENABLE_RPI_EEPROM_UPDATE=1 rpi-eeprom-update

BOOTLOADER: up to date
   CURRENT: Tue 06 Jul 2021 10:44:53 AM UTC (1625568293)
    LATEST: Tue 06 Jul 2021 10:44:53 AM UTC (1625568293)
   RELEASE: stable (/lib/firmware/raspberrypi/bootloader/stable)
            Use raspi-config to change the release.

  VL805_FW: Using bootloader EEPROM
     VL805: up to date
   CURRENT:
    LATEST:

The firmware version for “CURRENT” should match the exact version you used for pieeprom.original.bin in our curl command regardless of what is available in the repository.

Windows Firmware Update Instructions

For Windows you will need to follow the Linux instructions to get rpiboot (and more importantly the configuration files/scripts) on your Pi to generate the new pieeprom files using the Pi. After following the Linux instructions all the way to the end we will then need to copy the “recovery” folder to Windows where we will be able to run the final command using the Command Prompt (make sure you are in the same directory you copied the “recovery” folder from Linux to before running) of:

"C:\Program Files (x86)\Raspberry Pi\rpiboot.exe" -d recovery

or you can fully qualify your paths with:

"C:\Program Files (x86)\Raspberry Pi\rpiboot.exe" -d "C:\YourPathTo\recovery"

and upon connecting the IO board (with USB mass storage boot disabled using the jumpers) the firmware will be updated!

The process will be exactly the same as Linux except for the very last step since you aren’t going to be able to plug the running Compute Module 4 IO board into itself to perform the final update using the “recovery” folder. This is extra work if you don’t have an additional Pi / Linux PC available you can plug the IO board into but it can be done!

First Boot

You are now ready to boot your Compute Module 4. Go ahead and remove the jumper now from J2 and the pin below it. If you’re using a monitor connect it to the IO board first.

Now connect power to the IO board and the eMMC boot process will start. Your OS should boot with your preconfigured settings!

Benchmarking / Testing Storage

Once you’ve booted up you can verify your drive’s performance using my storage benchmark with:

sudo curl https://raw.githubusercontent.com/TheRemote/PiBenchmarks/master/Storage.sh | sudo bash

If you search for the model of your drive / eMMC / etc. on pibenchmarks.com you can compare your score with others and make sure the drive is performing correctly!

Conclusion

The Compute Module 4 is really interesting and fun to work with. It’s still pretty difficult, time consuming (including in shipping) and expensive to get a hold of these but they are extremely cool.

A Compute Module 4 setup with an IO board is actually the most powerful Pi setup there is (including vs the Pi 400) because it has access to PCI express and NVMe storage. This is a game changer and has resulted in a higher class of performance (as seen on my pibenchmarks.com storage benchmark) than has ever been possible on the Pi before.

If you are interested in getting started with NVMe check out my CM4 NVMe configuration guide!

This is all in a package that is only slightly larger than a Pi Zero but has much greater capabilities. It’s also the first Pi to ever have a built in eMMC storage! There’s a lot happening with these devices and I would expect a lot of these capabilities to start showing up in other Pis as well.

Overall it’s definitely worth exploring them and getting a “Compute Module 4” setup going if you are a Pi / SBC enthusiast or want to build your own products powered by a Pi!

guest
6 Comments
Inline Feedbacks
View all comments