How to install OpenWrt on a CM4-WRT-A router

By MyTechCatalog, 30 March, 2023

The first step is to generate a firmware image with all the necessary drivers to access the second Ethernet port (ETH1), NVME storage devices, as well as the i2c bus on the CM4-WRT-A router board.

There are at least two ways of achieving this goal. The first method, which is my favorite, involves running a script (in the Linux terminal) that builds a custom firmware image from scratch, in one masterstroke. The build script, available on my GitHub https://github.com/MyTechCatalog/cm4-wrt-a requires Docker, which can be installed via the terminal on Ubuntu or Debian by invoking the following commands:

Prepare Environment / Install Prerequisites

sudo apt update
sudo apt install -y docker.io
sudo usermod -aG docker $USER

That last command allows you to run Docker without having to use sudo. You may have to logout and back in again for it to take effect. You can test that everything is okay and ready to go by running the following command in the terminal:

docker run hello-world

You should see something like the following:

docker run hello-world output.

Building OpenWrt

  1. Clone the CM4-WRT-A repository:

    git clone https://github.com/MyTechCatalog/cm4-wrt-a.git
  2. Run the OpenWrt build script:

    cd cm4-wrt-a && ./build-openwrt.sh v22.03.4
  3. The OpenWrt images will be located in this folder: cm4-wrt-a/bin/targets/bcm27xx/bcm2711/

If you elected to, and successfully built OpenWrt, you can now jump to the section of this article where you prepare the CM4-WRT-A board for flashing, (assuming you have a CM4 with eMMC): https://www.mytechcatalog.com/how-to-install-openwrt-on-the-cm4-wrt-a-router#flashing-prep

The second method involves pasting some text in the official OpenWrt Firmware Selector tool, clicking a button, and after a minute or so, the tool generates links to a custom firmware image suitable for use on the CM4-WRT-A. The disadvantage of this method is that you don't get the picod package included, which is a service used to communicate with the Raspberry Pi Pico. The picod service enables you to view temperature measurements from the six sensors on the board in InfluxDB, or another tool such as Grafana (if you prefer), which can connect to an InfluxDB database.

Building a firmware image using the OpenWrt Firmware Selector

Open the OpenWrt Firmware Selector via the provided link. The query parameters in the link have already been setup to select the Raspberry Pi 4B/400/4CM (64bit) on the bcm27xx/bcm2711 platform. If you would like to change the base OpenWrt release this build will be based on, use the drop-down list on the top right.

You should see a page like the one shown in the figure below. Note the Model, Platform and Version. At the time of writing this article, the the latest version of OpenWrt was 22.03.3. Feel free to pick a more recent version from the drop down-list if it is indeed the case that there is a newer version available.

Click on Customize installed packages and/or first boot script.

OpenWrt Firmware Selector

This will reveal/open a box entitled Installed Packages containing the default package names in the selected OpenWrt release as shown below.

Customize installed packages and/or first boot script.

Copy the following package names into your clip board and after adding/typing a space at the end of the list in the Installed Packages box, paste the package names after the space you just added.

nstat lsblk kmod-r8169 r8169-firmware libi2c kmod-i2c-core kmod-i2c-bcm2835 kmod-nvme pciutils kmod-iwlwifi iwlwifi-firmware-ax200 iwlwifi-firmware-ax210 iperf3 htop nano-full luci

Next, click on the REQUEST BUILD button. A progress bar should appear as shown below.

Build in progress.

After a short time, less than a minute or so, it should say Build successful as shown below.

Build successful

The last four buttons now point to links to your custom OpenWrt firmware image suitable for flashing onto the CM4-WRT-A router board. Click on the first link to download the image.

OpenWrt firmware links

If you have a Raspberry Pi Compute Module 4 (CM4) with eMMC, it can only boot off of eMMC and cannot boot off of a microSD, as far as those two boot options are concerned. The converse is also true. The next section applies to CM4s with eMMC only.

#Preparing to flash the Raspberry Pi Compute Module 4 (CM4) using a CM4-WRT-A baseboard

The idea is to mount the eMMC on the CM4 as a USB Mass Storage device on a another computer, and use the Raspberry Pi Imager to flash the OpenWrt image that you just built following the steps above onto the CM4. You will need a computer running Linux. This works for a Mac too, however, I am only going to describe the Linux method here.

With power to the CM4-WRT-A board turned off, short/connect pins 3 and 4 on the header marked J14 (bottom right in the picture below), using a jumper or jumper wire.

CM4-WRT-A baseboard top with labels

Connect the CM4 USB2.0 port (top left in the figure above) to an available USB port on the computer and provide power to the CM4-WRT-A board (plug in and/or turn on the 12V power input).

Download and compile the source code of a tool called usbboot, that  is used to mount the CM4's eMMC storage:

sudo apt install git libusb-1.0-0-dev pkg-config
git clone --depth=1 https://github.com/raspberrypi/usbboot
cd usbboot
make
sudo ./rpiboot

If you are using a non Linux computer, or would like to checkout the original instructions, visit the usbboot github page.

Flashing the Raspberry Pi Compute Module 4 (CM4)

After executing the last instruction in the above code block, you should be able to see the boot volume mounted.

Use an application like the  Raspberry Pi Imager to flash the image onto the eMMC:

Raspberry Pi Imager

When the flashing is done, don't forget to eject the boot volume.

Raspberry Pi Imager

You can now unplug the USB cable from the CM4-WRT-A board, turn off its power, and remove the jumper across pins 3 and 4 on the header marked J14

Power up the CM4-WRT-A board again (without the jumper), and it will boot into OpenWrt. Connect an Ethernet cable directly between your computer and the ETH0 (LAN) port of the CM4-WRT-A board, and navigate to http://192.168.1.1 You should see a login screen similar to the one below: 

OpenWrt login screen

 

You can also login via the terminal using this command:  ssh root@192.168.1.1  Below is an example of output from running lspci and lsblk on a CM4-WRT-A terminal:

CM4-WRT-A lsblk and lspci output

 

Next: How to monitor the CM4-WRT-A board temperatures and fan speed (RPM) in InfluxDB.

Tags