Skip to content

Instantly share code, notes, and snippets.

@martin-niklasson
Last active August 31, 2025 20:24
Show Gist options
  • Select an option

  • Save martin-niklasson/6912a7e5ba49b92801d54766f1d7277a to your computer and use it in GitHub Desktop.

Select an option

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'
@vinnyt
Copy link

vinnyt commented Jul 26, 2021

Thank you for this. Is there another flag I would need to compile with to be able to run resize2fs so I can expand the filesystem on the pi when it is running?

@martin-niklasson
Copy link
Author

Thank you for this. Is there another flag I would need to compile with to be able to run resize2fs so I can expand the filesystem on the pi when it is running?

No. You cannot resize the partition on the running machine itself. This needs to be done by mounting the SD card or the eMMC flash on a separate Linux machine. DFRobot's wiki gives detailed instructions on how to expand the partition.

Otherwise, this should be it. You will have a running router with WAN, LAN and the web interface, so any software packages you need after this can easily be installed from the web interface.

@flipyou
Copy link

flipyou commented Aug 5, 2021

I followed this with rc3 and rc4, works great! only issue I've had is eth0 ends up dropping to 100Mbps intermittently unless you use ethtool to disable eee.

@ripplecart
Copy link

Thanks for the write-up @martin-niklasson! Tried it out with rc4 and it worked fine. Only thing is the orange LED does not light up on the LAN (RTL8111) port but the port itself works fine (green LED works as normal).

@martin-niklasson
Copy link
Author

martin-niklasson commented Aug 16, 2021

@ripplecart

Happy it worked for you. I noticed the missing orange LED myself, but both ethtool on the router and the switch on the other end report 1000Mbit/s full duplex, so I didn't dig deeper ;-)

@neetopia
Copy link

worth mentioning that you can expand the rootfs partition size with image builder as well, instead of expanding with fdisk afterwards.

@bit2016
Copy link

bit2016 commented Aug 21, 2022

@ripplecart

Happy it worked for you. I noticed the missing orange LED myself, but both ethtool on the router and the switch on the other end report 1000Mbit/s full duplex, so I didn't dig deeper ;-)

Same issue here, no orange LED on the RJ45 interface

@martin-niklasson
Copy link
Author

@bit2016

As I mentioned, you can easily verify with ethtool that the link actually is Gigabit. This is a cosmetic error.

root@claudius:~# ethtool eth1
Settings for eth1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
                                             1000baseT/Full
        Link partner advertised pause frame use: No
        Link partner advertised auto-negotiation: Yes
        Link partner advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 0
        Transceiver: external
        Auto-negotiation: on
        Supports Wake-on: pumbg
        Wake-on: d
        Current message level: 0x00000033 (51)
                               drv probe ifdown ifup
        Link detected: yes

@ETE-Design
Copy link

@martin-niklasson Is there an easy way to Compile it in Windows 11 with SubSystem Linux? Have some problems with it, cause it won't let me update Python to the Version required to Build... Also Now 22.03.0 is Released so you could update your readme, no need to add Luci anymore i think?
Also where exatly to place the Network before compile? Mine seems to fail, unless it just have something with wrong version of Python I use... Could I mabye ask you to compile it for me, only need I have is to change the Network IP for lan to 192.168.144.10

@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.

@ddschmitz
Copy link

Has anyone managed to get a recent OpenWRT image to build and run using this guide? Following the guide listed here as well as this one, I haven't been able to get anything to run on the DFRobot board.

The only thing I have managed to get to run is the image posted on their websites wiki but only after following the directions on this forum post. It seems as though they was a revision with the CM4 or an update in some firmware, and you need to just place the new files in the boot directory. Doing this I was able to get the board to boot and work. But I can't figure out how to get it to work with a newer build of OpenWRT.

@rudelm
Copy link

rudelm commented Aug 31, 2025

hey @ddschmitz I've found a workaround after my last comment and totally forgot this gist. For 23.05.0 onwords you have to only select kmod-usb-dwc2. To quote from my blog:

Everything else was either part of the package list or part of the Raspberry Pi base image (looking at bcm27xx-userland).

Maybe that helps. I've sold mine a few months ago and switched to a Unifi gateway instead, since the upgrade procedure was annoying. I suggest you try to create the bootimage like I've described and select only the kmod-usb-dwc2 package. Once the image is flashed, put the mentioned .dat and .elf firmware files into the /boot partition like it's recommended in the dfroboto forum. Hope that helps!

@ddschmitz
Copy link

@rudelm I appreciate the response on this really old gist haha!

While I don't think I followed your exact steps, it did lead me to try out the online firmware selector which I have heard about in the past but never tried. I gave this a shot following the steps mentioned in your blog and I was finally able to get a 24.X version written to the SD card that let me login to the web ui. Thank you! With the comfort of knowing I got an updated version working, I might see how my manual build compares to this online one and see if I can figure out what I'm doing wrong.

@rudelm
Copy link

rudelm commented Aug 31, 2025

Cool glad it worked out for you. I never got the local builds really working except for version 22 of OpenWRT. But even then the online firmware builder was working way better in my experience.

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