Applying Patches to OpenWrt Source Code
Applying Patches to a Package
OpenWrt utilizes the quilt tool to manage patches for its source packages. This allows you to download the upsteram source, verify it, and then apply your custom modifications before compilation.
For this example, we'll assume a develpoment environment based on Ubuntu 14.04 32-bit, targeting a device profile named my_board.
First, install the quilt utility:
sudo apt-get install quilt
Verify the installation:
$ quilt --help
Usage: quilt [--trace[=verbose]] [--quiltrc=XX] command [-h] ...
quilt --version
...
Let's use a package named my_package as a example. We want to add a new feature.
The standard compilation command is:
make PROFILE=my_board package/my_package/{clean,compile,install}
First, prepare the package for patching:
make PROFILE=my_board package/my_package/{clean,prepare} QUILT=1
Navigate to the package's source directory:
cd build_dir/target-arm-openwrt-linux-uclibc-my_board/my_package-1.0.2
Apply any existing patches:
quilt push -a
If no patches exist, you will see a message like:
No series file found
Create a new patch file. The patch number should be the next available integer. Since this is the first patch, we can name it 001-my-feature.patch:
$ quilt new 001-my-feature.patch
Patch 001-my-feature.patch is now on top
Edit the source files you wish to modify:
$ quilt edit ./include/my_package/header.h
You can edit multiple files. Once your changes are complete, view the differences:
quilt diff
Save your changes to the patch file:
quilt refresh
Return to the build directory and update the package's patch series:
make PROFILE=my_board package/my_package/update V=s
Upon success, the patch file will be located in the package's source directory:
# @ user in ~/openwrt/build_dir/target-arm-openwrt-linux-uclibc-my_board/my_package-1.0.2/patches [10:30:00]
$ ls
001-my-feature.patch
Recompile the package to include your changes:
make PROFILE=my_board package/my_package/{clean,compile,install}
Applying Patches to the Kernel
The process for applying patches to the Linux kernel is very similar to that of a package.
make target/linux/{clean,prepare} V=s QUILT=1
cd build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/linux-4.14.149/
quilt push -a
quilt new platform/666-reboot-softreset-2-hardreset-by-GPIO5.patch
quilt edit kernel/reboot.c
quilt edit other_file.c
quilt diff
quilt refresh
make target/linux/update V=s