Key takeaways
- Use the full buildroot for kernel, target and toolchain changes; the SDK for compiling packages against a released target; the Image Builder for assembling images from existing packages.
- Put your software in a separate feed with standard package Makefiles rather than editing the OpenWrt tree.
- Manage source changes as quilt patches and configuration as a checked-in diffconfig.
- Use the
files/overlay and/etc/uci-defaults/for defaults, not hand-edited images. - A pinned, CI-built, regularly rebased fork is what makes long-term maintenance affordable.
Most OpenWrt customisation projects go wrong in the same way: someone edits files directly in a source checkout, builds an image on their laptop, and six months later nobody can reproduce it or move it to the next release. OpenWrt has good tooling to avoid that. This post explains which tool to use when, and how to structure changes so they survive upgrades.
Buildroot, SDK and Image Builder
All three come from the same OpenWrt build system, but they solve different problems.
| Tool | What it does | Use it when |
|---|---|---|
| Buildroot (full source tree) | Builds toolchain, kernel, every package and images from source | Adding a board, changing kernel config or patches, changing target defaults, producing your own SDK and Image Builder |
| SDK | Prebuilt toolchain and headers for one target; compiles packages only | Building your own packages against a released or internal target without rebuilding everything |
| Image Builder | Assembles images from prebuilt packages; compiles nothing | Producing per-customer or per-SKU images quickly with different package lists and files |
The key constraint: packages that contain kernel modules must match the exact kernel they will run on. Use an SDK and Image Builder that came from the same build as your kernel, which in practice means generating your own from your buildroot when you have custom kernel changes. Enable them in make menuconfig with the top-level "Build the OpenWrt SDK" and "Build the OpenWrt Image Builder" options.
Feeds: keep your code out of the tree
Feeds are package collections that the build system pulls in. The default feeds.conf.default lists the upstream packages, LuCI, routing and telephony feeds. Add your own rather than dropping packages into package/:
# feeds.conf (copied from feeds.conf.default, then extended)
src-git packages https://git.openwrt.org/feed/packages.git
src-git luci https://git.openwrt.org/project/luci.git
src-git product https://git.example.com/acme/openwrt-feed.git
# then, in the shell:
./scripts/feeds update -a
./scripts/feeds install -a
During development, src-link pointing at a local directory saves a push for every change. For releases, pin every feed to a specific commit or tag in feeds.conf so the build is repeatable. Upstream release branches already pin their own feeds; do the same for yours.
Writing a custom package
A package is a directory with a Makefile, and usually files/ and patches/. Here is a minimal package for a small C daemon whose source lives in src/ beside the Makefile:
include $(TOPDIR)/rules.mk
PKG_NAME:=acme-agent
PKG_VERSION:=1.2.0
PKG_RELEASE:=1
PKG_LICENSE:=GPL-2.0-only
include $(INCLUDE_DIR)/package.mk
define Package/acme-agent
SECTION:=net
CATEGORY:=Network
TITLE:=ACME device management agent
DEPENDS:=+libubox +libubus +libuci
endef
define Package/acme-agent/description
Reports device state over ubus and applies UCI changes.
endef
define Package/acme-agent/conffiles
/etc/config/acme
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
$(TARGET_CONFIGURE_OPTS) \
CFLAGS="$(TARGET_CFLAGS)" LDFLAGS="$(TARGET_LDFLAGS)"
endef
define Package/acme-agent/install
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config
$(INSTALL_BIN) $(PKG_BUILD_DIR)/acme-agent $(1)/usr/sbin/
$(INSTALL_BIN) ./files/acme.init $(1)/etc/init.d/acme
$(INSTALL_CONF) ./files/acme.config $(1)/etc/config/acme
endef
$(eval $(call BuildPackage,acme-agent))
Points worth noting:
- For a real project, fetch source from a tagged release or git commit with
PKG_SOURCE_URLand a hash rather than copying local files; that keeps the package reproducible. - Projects using CMake, autotools or Meson can include the matching helper (for example
cmake.mk) and usually need noBuild/Compileat all. - Listing
/etc/config/acmeunderconffilesmeans upgrades preserve local edits. - Write the init script for procd (
USE_PROCD=1) so the daemon is supervised and restarted, and reloaded when its UCI config changes.
Build it on its own with make package/acme-agent/compile V=s in either the buildroot or the SDK.
Patching upstream code with quilt
When you need to change an existing package or the kernel, do it as a patch in the package's patches/ directory (or the target's kernel patch directory), never by editing build_dir and hoping. OpenWrt integrates quilt for this:
make package/example/{clean,prepare} V=s QUILT=1
cd build_dir/target-*/example-*/
quilt push -a # apply existing patches
quilt new 900-fix-timeout.patch
quilt edit src/main.c
quilt refresh
cd -
make package/example/update V=s # copies the patch back into package/.../patches/
The same flow works for the kernel with make target/linux/{clean,prepare} V=s QUILT=1 followed by make target/linux/update. Give each patch a header explaining why it exists and whether it has been sent upstream. That header is what saves you during a rebase.
Kernel configuration
Kernel options are layered: a generic config per kernel version, then target and subtarget configs. Use make kernel_menuconfig to change them; the result is written back to the target's config file in the tree, so it becomes a visible diff you can review. Prefer packaging optional drivers as kmod-* packages (via KernelPackage definitions) over building them in, so they can be included per SKU.
files/ overlay and uci-defaults
Anything placed in a top-level files/ directory in the buildroot (or passed with FILES= to the Image Builder) is copied into the root filesystem. It is the right place for banners, certificates and default config, but avoid overwriting whole UCI files that upstream also changes. For defaults, use first-boot scripts in /etc/uci-defaults/:
#!/bin/sh
# files/etc/uci-defaults/90-acme-defaults
uci -q batch <<'EOF'
set system.@system[0].hostname='acme-ap'
set system.@system[0].zonename='Asia/Kolkata'
set system.@system[0].timezone='IST-5:30'
EOF
uci commit system
exit 0
Scripts that exit 0 are deleted after running, so they run once on the first boot of every newly flashed image, including after a sysupgrade that keeps settings. Make them idempotent and check existing values before overwriting customer configuration. Per-device values such as a MAC-derived SSID can be computed in the script from /etc/board.json or the interface addresses.
With the Image Builder, a per-SKU image is then a single command:
make image PROFILE="acme_ap-1200" \
PACKAGES="acme-agent luci-theme-acme -ppp -ppp-mod-pppoe" \
FILES=files-sku-a/
Use make info in the Image Builder to list valid profiles.
Reproducible builds and CI
Treat the build as code:
- Store a diffconfig rather than a full
.config: generate it with./scripts/diffconfig.sh > diffconfig, and recreate the config withcp diffconfig .config && make defconfig. - Pin the OpenWrt tag or commit and every feed revision.
- Build in a container with a fixed host toolchain image, and cache the
dl/directory and, where safe, the toolchain. - OpenWrt derives
SOURCE_DATE_EPOCHfrom the source revision and the project works towards reproducible builds; avoid embedding build-host paths, usernames or timestamps in your own packages so identical inputs give comparable outputs. - Sign packages and images in a separate CI step with keys held outside the build machine, and archive the source and config for each release for GPL compliance.
Keeping a fork rebased on upstream
A product fork is cheap to maintain if it is small and expensive if it is not. The practical rules:
- Base on a stable release branch (for example openwrt-24.10 or openwrt-25.12), not a random snapshot, and follow its point releases.
- Keep your changes as a short, ordered series of commits on top of the upstream tag: board support, target tweaks, feed configuration. Everything else lives in your feed.
- Upstream board support and generic fixes. Each accepted patch is one fewer to carry.
- When a new major release lands, rebase in a branch, rebuild, and run your hardware test suite before moving SKUs over. Expect to revisit package names, kernel config symbols and, from 25.12 onwards, the move from opkg to apk.
Common pitfalls
- Mixing SDKs and kernels. Installing a
kmod-*package built against a different kernel fails at install time or, worse, loads and misbehaves. Build kernel modules from the same tree as the image. - Editing
build_dirorstaging_dir. Anything changed there disappears on the next clean. If it matters, it belongs in a patch, a package or the config. - Overlays that replace upstream defaults. Shipping a full
/etc/config/networkinfiles/breaks board-specific defaults generated from/etc/board.json. Adjust settings with uci-defaults instead. - Unpinned feeds. A build that tracks the head of a feed branch can change between two runs on the same day. Pin revisions for anything you release.
- Developer keys in production. The build system can generate a signing key automatically; make sure release images are signed with a controlled key, not one created on a build host.
How CloudWRT helps
Our R&D and OEM engineering services include custom OpenWrt builds and packages, kernel drivers, BSPs and build pipeline setup, so your product tree is reproducible and maintainable from day one.
For fleets in the field, the CloudWRT Platform handles scheduled firmware and configuration rollouts with rollback, plus configuration templates with variable substitution. Try it free.
Frequently asked questions
Can I use the official SDK if I changed the kernel?
Not safely for kernel modules. Kernel module packages must match the exact kernel build. Generate your own SDK and Image Builder from the buildroot that built your kernel.
Should defaults go in files/ or uci-defaults?
Use uci-defaults scripts for UCI settings, because they modify upstream defaults rather than replacing whole files. Use files/ for static assets such as banners, certificates and your own config files.
How often should we rebase onto upstream?
Follow every point release on your stable branch, which mostly brings security fixes, and plan a major-release migration roughly once a year while the old branch is still maintained.
Is the Image Builder enough for a white-label product?
Often yes, provided your board is supported in the build you generated it from. It is the fastest way to produce many SKUs with different package lists and overlays.