Changes between Initial Version and Version 1 of OpenWrt/Patch


Ignore:
Timestamp:
10/22/2017 05:28:45 AM (7 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OpenWrt/Patch

    v1 v1  
     1[[PageOutline]]
     2
     3= Patching OpenWrt =
     4
     5The OpenWrt Linux distribution like most other distributions consists of a build system that fetches, prepares, patches, compiles, and creates packages for various kernel and userspace components.  Often patches are necessary to upstream source to either make it appropriate for embedded systems, OpenWrt in general, or to simply add a feature or fix a bug that you need.
     6
     7The patch process is fairly straight-forward but does take some getting used to and can differ between kernel, out-of-tree kernel-modules, and userspace packages slightly.
     8
     9== Patching a Package ==
     10For this example we will patch busybox
     11
     12Steps:
     13 * shell1 cd to the OpenWrt trunk and prepare the package for development using quilt to track patches:
     14{{{
     15make package/busybox/{clean,prepare} QUILT=1 V=s
     16}}}
     17 * open a new shell2 into the package build directory (this differs depending on the target you are working with and the package name/version):
     18{{{
     19cd build_dir/target-arm_v6k_uClibc-0.9.33.2_eabi/busybox-1.19.4
     20}}}
     21 * understand the current patches:
     22{{{
     23quilt series ;# show all patches in series
     24quilt top ;# show current patch in series
     25quilt files ;# show files in the current patch
     26quilt diff ;# show the current patch
     27quilt refresh ;# update current patch
     28}}}
     29 * tell quilt you want to make a new patch
     30{{{
     31quilt new 999-fix_foo.patch
     32}}}
     33 * add/edit files to patch (using 'quilt edit' is a good way to avoid forgetting to add a file to a patch):
     34{{{
     35quilt edit foo/foo.c
     36}}}
     37 * in shell1 rebuild and test your package - repeat this edit/rebuild process until you are satisfied with your changes:
     38{{{
     39make package/busybox/{compile,install} V=s  ;# build
     40make package/index ;# rebuild package indexes if you are using opkg to update/test modules
     41make -j8 V=s ;# rebuild entire image if you are using that to test your changes
     42}}}
     43 * when satisfied update the patches in the kernel tree
     44{{{
     45make target/busybox/update ;# copy patches from build dir back to package dir
     46ls package/busybox/patches ;# notice your patch
     47}}}
     48
     49== Patching the Kernel ==
     50OpenWrt kernel patching differs from package patching in the following ways:
     51 * quilt is always enabled in the kernel tree
     52 * there are 2 sets of patches:
     53  * generic - from target/linux/generic/patches* that apply to the kernel in general
     54  * platform - from target/linux/<target>/patches* that apply to the target platform only
     55
     56Steps:
     57 * shell1 cd to the OpenWrt trunk and prepare the kernel for development using quilt to track patches:
     58{{{
     59make target/linux/{clean,prepare} V=s
     60}}}
     61 * open a new shell2 into the kernel build directory (this differs depending on the target/kernel you are working with):
     62{{{
     63cd build_dir/target-arm_v6k_uClibc-0.9.33.2_eabi/linux-cns3xxx/linux-3.8.6/
     64}}}
     65 * understand the current patches:
     66{{{
     67quilt series ;# show all patches in series
     68quilt top ;# show current patch in series
     69quilt files ;# show files in the current patch
     70quilt diff ;# show the current patch
     71quilt refresh ;# update current patch
     72}}}
     73 * tell quilt you want to make a new patch
     74{{{
     75quilt new platform/999-fix_foo.patch
     76}}}
     77 * add/edit files to patch (using 'quilt edit' is a good way to avoid forgetting to add a file to a patch):
     78{{{
     79quilt edit drivers/foo/foo.c
     80}}}
     81 * in shell1 rebuild and test your package - repeat this edit/rebuild process until you are satisfied with your changes:
     82{{{
     83make target/linux/{compile,install} V=s  ;# build kernel and modules
     84make package/index ;# rebuild package indexes if you are using opkg to update/test modules
     85make -j8 V=s ;# rebuild entire image if you are using that to test your kernel/modules
     86}}}
     87 * when satisfied update the patches in the kernel tree
     88{{{
     89make target/linux/update
     90}}}
     91
     92== Pushing patches upstream ==
     93It is highly recommended that you push your patches upstream so that you don't have to maintain them in the future.  This can be tricky as it is required that you apply/test/format your patch on the latest upstream OpenWrt.  You will have to decide if this is appropriate for you.  If you do not push your patch upstream you will need to maintain it in your build directory manually.  You can look at the scripts/makepatch script that Gateworks uses to maintain our patches against OpenWrt.  We strive to continually push our patches upstream.
     94
     95== Applying a .patch file to build ==
     96If a .patch file is acquired from somewhere, this is how you would apply it to a build of OpenWrt.
     97 1. Place the .patch file in the trunk directory
     98 2. Depending on the structure of the patch, do a dry run:
     99  1.
     100{{{
     101patch -p0 --dry-run < ath10kpatch.patch
     102}}}
     103 3. If the patch looks good, then apply the patch, knowing you will modify the code:
     104  1.
     105{{{
     106patch -p0 < ath10kpatch.patch
     107}}}
     108 4. Rebuild using make -j8 v=99 in the trunk directory now.