Skip to content

Instantly share code, notes, and snippets.

@martin-niklasson
Last active December 25, 2023 19:20
Show Gist options
  • Save martin-niklasson/6912a7e5ba49b92801d54766f1d7277a to your computer and use it in GitHub Desktop.
Save martin-niklasson/6912a7e5ba49b92801d54766f1d7277a to your computer and use it in GitHub Desktop.
How to make an up-to-date OpenWRT image for loading onto a Raspberry Pi Compute Module 4 with a DFRobot Router Carrier Board.

The background is that the default OpenWRT image for Raspberry Pi lacks drivers for the LAN port (RTL8111) on the DFRobot board. DFRobot provide an image, but that one is made from a quite old daily snapshot of OpenWRT which is not entirely stable. Also, it is better to know how to fish than be given a fish.

DFRobot's page about the router board:
https://wiki.dfrobot.com/Compute_Module_4_IoT_Router_Board_Mini_SKU_DFR0767

OpenWRT main page:
https://openwrt.org/

You are expected to have some general knowledge on Linux and OpenWRT. The instructions for flashing the resulting firmware image are presented on DFRobot's page.

We will use the OpenWRT image builder. This is a quite nifty tool that can generate a firmware image with some additional packages not present in the default image. It is not a cross-compiler, but rather takes already compiled OpenWRT packages and creates a new firmware image.

Download the latest image builder for Raspberry Pi from OpenWRT. At the time of writing, this is RC3. It is under target bcm27xx/bcm2711
https://downloads.openwrt.org/releases/21.02.0-rc3/targets/bcm27xx/bcm2711/

I built it on a Debian VirtualBox machine, but pretty much any Linux system would do. You first need to install some Linux tools. These are the tools for Debian/Ubuntu:

root@debian:~# apt install build-essential libncurses5-dev libncursesw5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc rsync wget unzip python

For other Linux distros, see the Prerequisites section here:
https://openwrt.org/docs/guide-user/additional-software/imagebuilder

Unpack your image builder:

martin@debian:~# tar Jxf openwrt-imagebuilder-21.02.0-rc3-bcm27xx-bcm2711.Linux-x86_64.tar.xz
martin@debian:~# cd openwrt-imagebuilder-21.02.0-rc3-bcm27xx-bcm2711.Linux-x86_64/

For some reason, you will need a /etc/config/network file in your image, or your LAN network will not come up.
https://openwrt.org/docs/guide-user/additional-software/imagebuilder#files_variable

martin@debian:~# mkdir -p files/etc/config

Put below file in files/etc/config/network

We need to build the image with 3 extra modules:

Go!

martin@debian:~# make image PROFILE="rpi-4" PACKAGES="luci kmod-r8169 kmod-usb-dwc2" FILES=files/

The built image(s) will end up at:
bin/targets/bcm27xx/bcm2711/

The “default” one to use would be:
openwrt-21.02.0-rc3-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz

After you gunzip that file, you can follow the instructions from DFRobot for installation. Or you can use “dd” directly on Linux, instead of Rufus:

martin@debian:~# dd if=/home/martin/openwrt/openwrt-21.02.0-rc3-bcm27xx-bcm2711-rpi-4-ext4-factory.img of=/dev/sdb
config interface 'loopback'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
option device 'lo'
config globals 'globals'
option ula_prefix 'fdff:ac50:10da::/48'
config interface 'wan'
option proto 'dhcp'
option device 'eth0'
config interface 'lan'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
option device 'eth1'
@rudelm
Copy link

rudelm commented Oct 19, 2023

Hi @martin-niklasson did you manage to create an image for the DFRobot board under OpenWRT 23.05.0 yet? I'm having troubles with bcm27xx-userland

Collected errors:
 * opkg_conf_parse_file: Duplicate src declaration (openwrt_core https://downloads.openwrt.org/releases/23.05.0/targets/bcm27xx/bcm2711/packages). Skipping.
 * opkg_conf_parse_file: Duplicate src declaration (openwrt_base https://downloads.openwrt.org/releases/23.05.0/packages/aarch64_cortex-a72/base). Skipping.
 * opkg_conf_parse_file: Duplicate src declaration (openwrt_luci https://downloads.openwrt.org/releases/23.05.0/packages/aarch64_cortex-a72/luci). Skipping.
 * opkg_conf_parse_file: Duplicate src declaration (openwrt_packages https://downloads.openwrt.org/releases/23.05.0/packages/aarch64_cortex-a72/packages). Skipping.
 * opkg_conf_parse_file: Duplicate src declaration (openwrt_routing https://downloads.openwrt.org/releases/23.05.0/packages/aarch64_cortex-a72/routing). Skipping.
 * opkg_conf_parse_file: Duplicate src declaration (openwrt_telephony https://downloads.openwrt.org/releases/23.05.0/packages/aarch64_cortex-a72/telephony). Skipping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment