How to Flash/Write Raspbian OS onto Raspberry Pi Compute Module 4 (CM4)

Updated 14 February 2022

While the Raspberry Pi Compute Module 4s (CM4s) share a lot with the regular Pi 4 Model B, getting started with the flashing process can be quite different depending on which model you pick! This article aims to demystify that, so without further ado, let's get cracking!

You will need to mount your CM4 module on carrier board with a USB port or micro-SD card slot for this process. We'll be using the official CM4 IO Board as the carrier for this guide. The process will be similar for all CM4 carrier boards although you might need to check the documentation for how they've wired up the USB interface and how to disable eMMC booting (more on that later).

You'll also need a computer connected to the internet, a USB Cable or a micro-SD Card (depending on whether your CM4 has eMMC or not), and a power supply.

eMMC or Micro-SD?

The first step to determining how to flash your CM4 is to work out whether your board has embedded Multi-Media Card storage. As the name suggests, it's like the Micro-SD cards you're familiar with, but soldered right onto the CM4. It connects to the same pins on the BCM chip as an SD card would, meaning you can either have onboard eMMC storage, or boot a CM4 from an SD card, but not both.

CM4s with eMMC are usually marked as such in their product names, and those without are marked with "Lite". If you aren't sure whether the CM4 in front of you has eMMC, you can spot the eMMC as a large IC sitting above the BCM chip:

Comparison between CM4 modules with and without on board eMMC

If you've got a CM4 with eMMC and would like to use an SD card for storage, you'll need to use a USB SD Card reader (and you'll need to enable the USB ports). In theory you could boot from a USB SD card reader, but it will depend on the design of your specific card reader whether you can in practice.

Preparing to flash eMMC models

If your CM4 has onboard eMMC, there are some additional steps you need to take to prepare it for flashing. If you've got one of the Lite models, you can insert your SD card in your PC and skip ahead.

The order in which you make connections is important to the success of this process, so before we begin, remove all power and other connections from your CM4 Carrier board (but keep your CM4 mounted).

  1. Download and install rpiboot from the Pi Foundation Github:

    Windows: Just download and run the pre-built installer from usbboot/win32/rpiboot_setup.exe

    Mac OS: Enter the following terminal commands to install git (if it's not already installed), clone the github repo to your machine, install the dependencies, then compile.

    brew install git
    git clone --depth=1 https://github.com/raspberrypi/usbboot
    cd usbboot
    brew install libusb
    brew install pkg-config
    make

    Linux or Raspberry Pi OS: Enter the following terminal commands to install git (if it's not already installed), clone the github repo to your machine, install the dependencies, then compile.

    sudo apt update
    sudo apt install git
    git clone --depth=1 https://github.com/raspberrypi/usbboot
    cd usbboot
    sudo apt install libusb-1.0-0-dev
    make
  2. Connect the nRPIBOOT pin (pin 93) to ground.
    Somewhere on your carrier board, there'll be a jumper marked BOOT, nRPIBOOT, or disable eMMC Boot. Make sure you install a jumper on this pin to connect it to GND. This will prevent the CM4 from trying to boot from the eMMC, allow the eMMC to appear to your computer as an external storage device, and thus allow us to flash or write an OS to the eMMC.
    Here is the disable eMMC BOOT jumper location on the CM4 IO Board:
    CM4 IO Board Boot Jumper Location
  3. Connect your carrier board to your host PC or Pi with a USB cable to the USB Slave port on your carrier board, making sure you have set up the board to disable eMMC booting and installed rpiboot as described above.
    On the official CM4 IO Board, the USB slave port is on the micro usb connector, just between the USB A ports and the micro-SD card slot:
    Location of the micro USB slave port on the CM4 IO Board
  4. Apply power to the board via the 12v barrel jack input. Note, some carrier boards, like Seeed Studio's gigabit ethernet carrier only have one USB port for power and data, so you'll need to make sure your host device can supply plenty of current if this is the case (avoid using USB hubs to save some potential headaches).
  5. Run rpiboot which we installed in step 2:

    Windows: Open your start menu and search for rpiboot, then run it.

    Raspberry Pi, Linux, and Mac OS: Run the terminal command

    sudo ./rpiboot
    This will open and setup the driver software you installed in step 2, and all going well, will recognise the CM4's eMMC as a drive, and mount it. Note that the eMMC won't appear in your file explorer as a drve until it's been formatted, as it  has no filesystem for you to write files to from the factory.

Flashing Procedure for Lite and eMMC Models

From here on (or if your CM4 has no eMMC and you're using a micro-SD card), the flashing process is pretty much the same as for a regular Pi 4:

  1. Make sure you've got the latest version of the Raspberry Pi Imager installed, and open it.
  2. If you're using an SD Card, insert your Micro-SD card into a slot on your PC or a USB reader.
  3. Run Raspberry Pi Imager and pick an OS with the Choose OS button. Raspberry Pi OS (32-bit) is the standard at the time of writing:
    Raspberry Pi Imager - Choose an OS

  4. Select the target device to flash to with Choose Storage. The Pi imager is smart, so it'll only show you external devices, and you should see yours on the list, whether it's a micro-SD card or the eMMC:
    Raspberry Pi Imager - Choose storage
    If the eMMC does not appear as a storage option, try again from the beginning. Make sure you've made the connections in the correct order (BOOT jumper, USB, then Power), and have correctly installed rpiboot.
  5. Hit Write to erase everything on that drive, download your chosen OS, and flash your chosen OS to your chosen storage. Make yourself a cuppa and come back when it's finished.
  6. That's it! It's ready to boot, though if you need to use the USB ports on your carrier board (for a mouse and keyboard say), see below.

Enabling the USB Ports (optional)

You won't be able to use a USB mouse or keyboard with your CM4 until you enable the USB Ports. In order to save power in embedded applications, the CM4 Modules ship with the USB interface disabled by default (see section 2.4 in the CM4 datasheet).

  1. Open up your freshly flashed SD card or eMMC in your file manager (Explorer on Windows).
  2. Open /boot/config.txt in your favourite text editor.
  3. Append
    dtoverlay=dwc2,dr_mode=host
    and save the file.

Boot it up!

You can now safely disconnect your CM4 from power, eject your SD card or disconnect your CM4 and Computer, remove the BOOT jumper, then start up your CM4 just like it was any other Pi.

Troubleshooting tips

For MacOS, this guide assumes you already have Homebrew installed. If not, you'll need to install it first before any of the brew commands will work in your terminal.

You will need to make sure the time and date are accurately set on your PC or Pi, else the git commands might fail. The time should automatically synchronise with a time server if you're connected to the internet, but you may need to set the time manually if this fails for some reason.

To manually set the time on a Pi, first, make sure you've set your timezone correctly (in the 'Localisation' options in raspi-config). Then in a terminal window, enter:

sudo date MMDDhhmmYYYY

Where MM, DD, hh, mm, YYYY, are the digits of the Month, Day, hours, minutes, and Years, respectively, in your local time. Make sure to include leading zeros.

Further resources

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.