Key takeaways
- Back up the full flash before you change anything; the factory or art partition holds per-unit calibration and MACs that cannot be regenerated.
- A port is mostly three files: the device tree, a device definition in
target/linux/<target>/image/*.mk, and board.d entries. - Describe calibration data and MAC addresses as NVMEM cells in the DTS rather than with shell fixups.
- Boot an initramfs image over TFTP first; only write flash once the hardware works.
- Upstreaming the port is the cheapest way to keep it maintained.
Porting OpenWrt to a board built on an already-supported SoC is mostly careful description work: telling the kernel where everything is, and telling the build system how to package an image the bootloader will accept. Here is the process we follow, with generic examples. File paths and helper names vary by target, so always read a few existing devices in the same target before writing your own.
1. Gather hardware information
Start with the board, the stock firmware and a serial console.
- UART. Find the TX, RX and GND pads (usually a 3.3 V TTL header; never connect a 5 V or RS-232 adapter). Common baud rates are 115200 or 57600. The bootloader log tells you the SoC revision, RAM size, flash chip and often the partition layout.
- Bootloader. Note the U-Boot version, whether you can interrupt it, whether it supports TFTP, and which image formats it boots (legacy uImage, FIT or a vendor header). Check whether it verifies signatures.
- Flash layout. From the stock firmware, record
/proc/mtd, the kernel command line and boot log. Back up every partition, or read the whole chip with an SPI programmer if the board allows it. - GPIOs. Map LEDs and buttons. A stock device tree blob, extracted from the vendor image and decompiled with
dtc, often gives you most of this directly; otherwise test pins from a shell. - Switch and PHYs. Identify the switch, which ports are wired to which labels on the case, the CPU port, and any external PHYs.
- Radios. Identify each Wi-Fi chip (on-SoC or PCIe), its driver in OpenWrt, and where its calibration data lives in flash, plus where the base MAC address is stored.
# On the stock firmware, if a shell is available
cat /proc/mtd
cat /proc/cmdline
dmesg > /tmp/boot.log
# copy each /dev/mtdN to external storage before going further
Warning: The partition named factory, art or similar contains per-unit radio calibration and MAC addresses. If it is erased, the radio may still work but with wrong power levels and out of regulatory limits. Keep a backup for every unit you develop on.
2. Write the device tree
Create a DTS for the board in the target's DTS directory, including the SoC's .dtsi. The DTS describes everything board-specific: model and compatible string, flash partitions, LEDs, buttons, Ethernet ports and radios. The first compatible string (for example acme,ap-1200) becomes the board name OpenWrt uses everywhere else.
A trimmed, illustrative example for a MediaTek MT7621 board:
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "mt7621.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
/ {
compatible = "acme,ap-1200", "mediatek,mt7621-soc";
model = "ACME AP-1200";
aliases {
led-boot = &led_status;
led-failsafe = &led_status;
led-running = &led_status;
led-upgrade = &led_status;
};
keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
};
leds {
compatible = "gpio-leds";
led_status: led-0 {
color = <LED_COLOR_ID_GREEN>;
function = LED_FUNCTION_STATUS;
gpios = <&gpio 15 GPIO_ACTIVE_HIGH>;
};
};
};
&spi0 {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 { label = "u-boot"; reg = <0x0 0x30000>; read-only; };
partition@30000 { label = "u-boot-env"; reg = <0x30000 0x10000>; read-only; };
partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
read-only;
nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;
eeprom_factory_0: eeprom@0 { reg = <0x0 0x400>; };
macaddr_factory_4: macaddr@4 { reg = <0x4 0x6>; };
};
};
partition@50000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x50000 0xfb0000>;
};
};
};
};
The firmware partition is split at runtime into kernel, squashfs rootfs and the writable rootfs_data overlay. Check the binding names (LED properties, the NVMEM layout syntax, the flash compatible) against the kernel version your OpenWrt release uses, as these have changed over time.
3. Add the image recipe
Each device gets a definition in the target's image makefile, for example target/linux/ramips/image/mt7621.mk. It names the device, sets the maximum image size (which must match the firmware partition), lists device-specific packages and, if needed, describes how to build images the stock firmware or bootloader will accept.
define Device/acme_ap-1200
IMAGE_SIZE := 16064k
DEVICE_VENDOR := ACME
DEVICE_MODEL := AP-1200
DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2
endef
TARGET_DEVICES += acme_ap-1200
The 16064k value is the 0xfb0000 firmware partition from the DTS. On most targets the device name maps to the DTS file name by convention, and the default recipes produce a sysupgrade image with metadata that sysupgrade checks against the board name. Two image types matter:
- sysupgrade: used from a running OpenWrt system; carries metadata and is checked against
SUPPORTED_DEVICES. - factory: used for the first install from the stock web UI or bootloader; may need a vendor header, checksum or specific padding, built with helpers from the target's image commands.
Add an initramfs image to the build as well. Loading it into RAM from U-Boot over TFTP lets you test the whole port without touching flash.
4. Board scripts: network and LEDs
On first boot, scripts in /etc/board.d/ generate /etc/board.json, which in turn seeds the default /etc/config/network and system LED configuration. In the source tree they live under the target's base-files/etc/board.d/. Add a case for your board name:
# target/linux/ramips/mt7621/base-files/etc/board.d/02_network (excerpt)
acme,ap-1200)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
;;
# 01_leds (excerpt)
acme,ap-1200)
ucidef_set_led_netdev "wan" "WAN" "green:wan" "wan" # needs a green WAN LED (function = LED_FUNCTION_WAN) in the DTS
;;
With DSA, port names come from the switch node labels in the DTS, so keep them matching the case. Many LED behaviours can now be expressed directly in the DTS as default triggers, which is preferable where it works.
5. Wi-Fi calibration and MAC addresses
Radio drivers need the per-unit calibration data from flash. Modern OpenWrt describes it as NVMEM cells, as in the DTS above, and references them from the radio node:
&pcie0 {
wifi@0,0 {
compatible = "mediatek,mt76";
reg = <0x0000 0 0 0 0>;
nvmem-cells = <&eeprom_factory_0>;
nvmem-cell-names = "eeprom";
};
};
&gmac0 {
nvmem-cells = <&macaddr_factory_4>;
nvmem-cell-names = "mac-address";
};
Cell names differ by driver (for example ath9k and ath10k use calibration-related names rather than eeprom), so copy the pattern from an existing board using the same radio. Where the vendor stores one base MAC and derives others by increment, newer kernels support expressing that in the NVMEM layout; older ports used shell fixups in board scripts. Prefer the DTS approach and verify every interface MAC against the label and the stock firmware.
6. Testing checklist
| Area | What to verify |
|---|---|
| Boot | Initramfs boots; flashed image boots cold and warm; failsafe mode works via the reset button |
| Flash | Partitions match the backup; overlay mounts; settings persist across reboot |
| Upgrade | Factory image installs from stock; sysupgrade with and without -n; image size check rejects oversized images |
| Ethernet | Every port links at expected speeds; port labels match case; VLANs via DSA work |
| Wi-Fi | All radios detected; throughput and TX power sane; correct country code behaviour |
| MACs | Interface MACs match label and stock firmware; no random MACs after reboot |
| LEDs and buttons | Status LED follows boot, failsafe and upgrade states; reset and WPS buttons trigger |
| Stability | Multi-hour traffic soak with clients; no kernel warnings in the log |
7. Upstreaming
Submitting the port to OpenWrt means it is rebuilt and kept compiling with every kernel bump, and others will fix it alongside their own boards. Upstream expects one commit per device with a prefix naming the target, a description of the hardware specification, installation and recovery instructions, MAC address assignments, and a Signed-off-by line. Follow the current submission guidelines on the OpenWrt developer pages and look at recently merged device commits for the expected format. Run the checks that reviewers will run and respond to review comments promptly; ports that follow the target's existing conventions are merged much faster.
Board-specific secrets, proprietary packages and branding stay in your own feed and overlay, as described in OpenWrt SDK customisation explained.
How CloudWRT helps
Board bring-up, BSPs, kernel drivers and custom OpenWrt builds are core parts of our R&D and OEM engineering services. We can take a board from first serial output to a tested image and, where you want it, an upstream submission.
Once the port runs, the device can be managed from the CloudWRT Platform alongside OpenWrt-compatible hardware from other ODMs (see bring your own hardware). For the wider product picture, read how to build commercial routers using OpenWrt.
Frequently asked questions
How long does an OpenWrt port take?
On an already-supported SoC with standard radios, the core port is usually a matter of days to a few weeks, depending on bootloader quirks and factory image formats. A new SoC or an unsupported Wi-Fi chip is a much larger driver project.
Do we need the stock firmware source?
It helps but is not required. The boot log, partition table, stock device tree blob and a flash backup usually provide what the port needs. GPL source from the vendor can clarify GPIO and switch details.
What if the bootloader only accepts signed images?
Then you need the vendor's signing process, a bootloader replacement where that is legally and technically possible, or a chain-loading approach. Establish this before committing to the hardware.
Should our port go upstream?
For most products, yes. Upstream support removes a large part of the rebase work at each release. Proprietary parts stay in your own feed.