
Auto-Replace OpenWRT Kernel
You want repeatable builds without mystery failures, and Auto-Replace OpenWRT Kernel shows where to make that reliable. We’ll point to the files and switches that control per-target versioning so you can stop guessing and start tracking every change.
I’ll show the practical bits — where KERNEL_PATCHVER lives, how to keep per-version configs and patches in the tree, and the commands we run to rebuild a target without interactive prompts. This short guide keeps things concrete: simple paths, exact commands, and real examples you can adapt for ar71xx and x86 platforms.
Key Takeaways
- Set KERNEL_PATCHVER in the platform Makefile to control the version per target.
- Keep versioned config- files and patches- directories under target/linux for traceability.
- Use make target/linux/clean and make target/linux/compile to rebuild deterministically.
- Separate .config edits from kernel config changes to avoid interactive prompts.
- Cache sources and add guardrails to save build time and reduce flaky runs.
Why automate OpenWrt kernel updates and what to expect today
Keeping version changes predictable saves time when a fleet of devices needs consistent images.
Kernel ABI shifts break binary compatibility. That means prebuilt packages will not install until you rebuild them. opkg may fail on install until feeds and packages match the new ABI.
In the build tree, .config controls package selection and build options. Per-target kernel config files live under target/linux/<arch>/config-*. Use make kernel_menuconfig to set those values so builds don’t stop for prompts.
We script the bump so the system does the heavy lifting: update include files, align patches, sync feeds, and trigger package rebuilds. Expect some issues — patch rejects or missing CONFIG entries are common. Build those checks into your answer playbook.
Impact | Likely Action | Scope |
---|---|---|
ABI change | Rebuild all packages | Entire device fleet |
Missing CONFIG | Commit to target config- file | Per target |
Patch rejects | Update or drop patch | Platform-specific |
Prepare your build system, feeds, and target configuration
We begin with the essentials: an updated feed set, a healthy toolchain, and a verified source tree.
Environment setup: sync feeds and run the tooling commands you trust—make feed update; make feed install; then make download. Confirm your source hashes and toolchain integrity before changing any config files.
Know the directory layout
Locate shared and platform files quickly. target/linux/generic holds common config and patches. target/linux/<target> stores per-target files. During a build, build_dir contains the unpacked sources you will inspect.
.config vs kernel config
Use make menuconfig to edit the root .config—this controls package selection and global build options. Use make kernel_menuconfig to edit the kernel config that gets saved to target/linux/<arch>/config-<ver>.
- Prefer built-in (*) for critical kernel choices rather than module (M).
- If the build prompts after kernel_menuconfig, add explicit CONFIG lines to the target config file.
- Keep a default baseline config per target and commit both the .config and target configs to version control.
Item | Location | Why it matters |
---|---|---|
Shared patches | target/linux/generic | Reused across platforms |
Platform config | target/linux/<target> | Target-specific options |
Unpacked sources | build_dir | Debug and patch application |
How to auto compile OpenWRT kernel updates step by step
Start by pinning the kernel version in the target Makefile so every build follows the same source line.
Set KERNEL_PATCHVER in target/linux/<platform>/Makefile. Then add an include/kernel-<version> file that lists the tarball and a SHA256 generated with staging_dir/host/bin/mkhash sha256.
- Create versioned config files. Copy generic/config-<old> to generic/config-<new> and mirror that under target/linux/<platform> so file names match the version.
- Organize patches. Place patches in target/linux/<platform>/patches-<version> and prefix filenames (100-, 200-) to enforce order and predictable application.
- Script the build line. Use a small script that runs:
make target/linux/clean
;make target/linux/compile V=s
; thenmake target/linux/install
. Wrap withset -e
and verbose logging to capture every line. - CI and caching. Cache the dl/ directory and verify source hashes before the build to cut minutes from each run and avoid transient errors.
When a patch fails — for example, “Hunk FAILED in lib/Makefile … Error 2” — refresh the patch against the new source or edit the context lines. For quick edits in build_dir, re-run the compile and install commands so artifacts update in the image staging outputs.
Step | Command / File | Why it matters |
---|---|---|
Pin version | target/linux/<platform>/Makefile (KERNEL_PATCHVER) | Locks the source and file selection per target |
Include file | include/kernel-<version> (sha256) | Ensures the build downloads the right source |
Patch set | target/linux/<platform>/patches-<version> | Ordered application reduces patch drift |
Build script | make target/linux/clean; compile; install | Reproducible line-by-line artifacts |
Version and platform examples to guide your configuration
I walk through two real cases—one x86 upgrade and one Atheros downgrade—to show exact file edits and the commands I run for verification.
x86 example: 5.10 → 5.16
Edit target/linux/x86/Makefile to point at 5.16 and add an include/kernel-5.16 file. Generate the sha256 with ${openwrt_topdir}/staging_dir/host/bin/mkhash sha256 linux-5.16.tar.xz and store that include file in-tree.
Copy generic/config-5.10 → generic/config-5.16 and mirror x86-specific config files into target/linux/x86/ and its subdirectories.
Validate with the command sequence: make target/linux/clean; make target/linux/compile V=s. Confirm the include/kernel-5.16 hash matches your tarball.
Atheros ar71xx example: 3.18 → 3.17
Set KERNEL_PATCHVER:=3.17 in target/linux/ar71xx/Makefile. Copy generic/config-3.18 → config-3.17 and place platform copies under target/linux/ar71xx/.
Create target/linux/ar71xx/patches-3.17 and add patches with numeric prefixes to enforce order.
If a patch like 310-lib-add-rle-decompression.patch fails with Hunk FAILED in lib/Makefile, refresh the patch against linux-3.17 or adjust context lines to match the source tree.
Platform | Key file | Validation step |
---|---|---|
x86 | include/kernel-5.16 | mkhash + compile run |
ar71xx | target/linux/ar71xx/Makefile | set KERNEL_PATCHVER + patch apply |
Both | target/linux/generic/config-* | copy configs + test build |
Keep concise commit messages linking each file change to the version transition. A short internal post with the working branch and a quick “thanks” saves teammates time and encourages reuse.
Troubleshooting common build issues and questions
When builds fail, the logs tell the story—read them first and you’ll solve most problems quickly.
I’ll walk through the usual error patterns and the practical way to address each. Keep short notes for repeat cases so the next time you hit the same problem you act faster.
Patch failures and rejects
If you see a message like “Hunk FAILED in lib/Makefile … 1 out of 1 hunk FAILED … Error 2,” the patch context is stale.
- Open the log, note the file and hunk offsets, then regenerate the patch against the current source.
- If the code moved, refresh the patch or adjust offsets and reapply.
Interactive prompts and missing CONFIG
Repeated questions come from missing entries in target config files.
Edit the target .config or append lines like #CONFIG_GENERIC_CPUFREQ_CPU0 is not set
to silence prompts.
Editing source and forcing rebuilds
Modify files in build_dir, then run the target/linux/compile and target/linux/install steps to update artifacts and see the result.
Packages, feeds, and opkg
ABI shifts cause opkg failures. Rebuild packages, refresh feeds, and publish matching artifacts so the package manager finds compatible files.
Issue | Quick way | Result |
---|---|---|
Patch reject | Regenerate patch | Apply cleanly |
Interactive prompt | Add CONFIG line | No prompts |
opkg error | Rebuild packages | Installable artifacts |
Platform case | Compare config files | Find delta |
Best practices to keep your OpenWrt kernel automation reliable over months and years
Treat each version bump like a small release. Pin the version in the tree, commit target config-*
files, and store include hashes so your system behaves the same in months and years.
Cache feeds and source tarballs in CI to speed building and avoid transient failures. Keep patches organized per version and prefer built-in options over module for critical features.
Automate package and packages rebuilds after every version change, refresh feeds so opkg sees compatible artifacts, and add guardrails to scripts—fail fast, log commands, and upload a triage page.
Make small, frequent changes, plan rollbacks, and post short notes with what worked and the final result. That way we answer problems faster and keep devices stable over months and years.