openwrt补丁

http://wiki.openwrt.org/doc/devel/patches

Working with patches

OpenWrt Buildroot integrates quilt for easy patch management. This document outlines some common patching tasks like adding a new patch or editing existing ones.

Prepare quilt configuration

In order to let quilt create patches in OpenWrts preferred format, a configuration file .quiltrc containing common diff and patch options must be created in the local home directory.

cat > ~/.quiltrc <<EOF
QUILT_DIFF_ARGS="--no-timestamps --no-index -pab --color=auto"
QUILT_REFRESH_ARGS="--no-timestamps --no-index -pab"
QUILT_PATCH_OPTS="--unified"
QUILT_DIFF_OPTS="-p"
EDITOR="nano"
EOF
  • EDITOR specifies the preferred editor for interactive patch editing
  • The other variables control the patch format property like a/, b/ directory names and no timestamps
  • FreeBSD does not support the --color=auto option and -pab must be written as -p ab

Adding a new patch

To add a completely new patch to an existing package example start with preparing the source directory:

make package/example/{clean,prepare} V=s QUILT=1

For host-side packages, you may want to detail the make target:

make package/example/host/{clean,prepare} V=s QUILT=1

This unpacks the source tarball and prepares existing patches as quilt patch series (if any). The verbose output will show where the source got extracted.

Change to the prepared source directory.

cd build_dir/target-*/example-*

Note : It can happen that you need to go one level lower as the source is extracted in build_dir/target-*/BUILD_VARIANT/example-* . This happens when multiple build variants of a package are defined in the Makefile.

Apply all existing patches using quilt push.

quilt push -a

Create a new, empty patch file with the quilt new command:

quilt new 010-main_code_fix.patch
  • The name should start with a number, followed by a hyphen and a very short description of what is changed
  • The choosen number should be higher than any existing patch - use quilt series to see the list of patches
  • The patch file name should be short but descriptive

After creating the empty patch, files to edit must be associated with it. The quilt add command can be used for that - once the file got added it can be edited as usual.

A shortcut for both adding a file and open it in an editor is the quilt edit command:

quilt edit src/main.c
  • src/main.c gets added to 010-main_code_fix.patch
  • The file is opened in the editor specified with EDITOR in .quiltrc

Repeat that for any file that needs to be edited.

After the changes are finished, they can be reviewed with the quilt diff command.

quilt diff

If the diff looks okay, proceed with quilt refresh to update the 010-main_code_fix.patch
file with the changes made.

quilt refresh

Change back to the toplevel directory of the buildroot.

cd ../../../

To move the new patch file over to the buildroot, run update on the package:

make package/example/update V=s

Finally rebuild the package to test the changes:

make package/example/{clean,compile} package/index V=s

If problems occur, the patch needs to be edited again to solve the issues.
Refer to the section below to learn how to edit existing patches.

Edit an existing patch

Start with preparing the source directory:

make package/example/{clean,prepare} V=s QUILT=1

Change to the prepared source directory.

cd build_dir/target-*/example-*

List the patches available:

quilt series

Advance to the patch that needs to be edited:

quilt push 010-main_code_fix.patch
  • When passing a valid patch filename to push, quilt will only apply the series until it reaches the specified patch
  • If unsure, use quilt series to see existing patches and quilt top to see the current position
  • If the current position is beyound the desired patch, use quilt pop to remove patches in the reverse order

Edit the patched files using the quilt edit command, repeat for every file that needs changes.

quilt edit src/main.c

Check which files are to be included in the patch:

quilt files

Review the changes with quilt diff.

quilt diff

If the diff looks okay, proceed with quilt refresh to update the current patch with the changes made.

quilt refresh

Change back to the toplevel diretory of the buildroot.

cd ../../../

To move the updated patch file over to the buildroot, run update on the package:

make package/example/update V=s

Finally rebuild the package to test the changes:

make package/example/{clean,compile} package/index V=s

Adding or editing kernel patches

The process for modifying kernel patches is the same as for packages, only the make targets and directories differ.

For the kernel, an additional subdirectory for patches is used, generic/ contains patches common to all architectures and platform/ contains patches specific to the current target.

To prepare the kernel tree, use:

make target/linux/{clean,prepare} V=s QUILT=1

For Attitude Adjustment, the source tree is in the linux-architecture subdirectory:

cd build_dir/linux-*/linux-3.*

For Barrier Breaker (trunk), the source tree is in the target-architecture subdirectory (potentially with a subarch):

cd build_dir/target-*/linux-*/linux-3.*

Moving the changes back over to the buildroot tree from the build tree is done with:

make target/linux/update package/index V=s

(
Patches should be named with the correct prefix, platform/000-abc.patch
or generic/000-abc.patch. If not the update may not work correctly.)

Afterwards, if we want to verify whether our patch is applied or not, we can go to the top level directory with

cd ../../../../

and preparing again the linux folder for some modification with

make target/linux/{clean,prepare} V=s QUILT=1

During this process all the applied patched will be shown, ours being among them, preceeded by generic/ or platform/ depending on what directory we placed the patch. Another way of retrieving the applied patches is through

quilt series

as explained on the previous sections, after having made make target/linux/{clean,prepare} …

Adding or editing toolchain patches

For example, gcc:

To prepare the tool tree, use:

make toolchain/gcc/{clean,prepare} V=99 QUILT=1

The source tree depends on chosen lib and gcc :

cd build_dir/toolchain-mips_r2_gcc-4.3.3+cs_uClibc-0.9.30.1/gcc-4.3.3

Refreshing the patches is done with:

make toolchain/gcc/update V=99

Refreshing patches

When a patched package (or kernel) is updated to a newer version, existing patches might not
apply cleanly anymore and patch will report fuzz when applying them. To rebase the
whole patch series the refresh make target can be used:

make package/example/refresh V=s

For kernels, use:

make target/linux/refresh V=s

Iteratively modify patches without cleaning the source tree

When implementing new changes, it is often required to edit patches multiple times.
To speed up the process, it is possible to retain the prepared source tree between
edit operations.

  1. Initially prepare the source tree as documented above
  2. Change to the prepared source directory
  3. Advance to the patch needing changes
  4. Edit the files and refresh the patch
  5. Fully apply the remaining patches using quilt push -a (if any)
  6. From the toplevel directory, run make package/example/{compile,install} or make target/linux/{compile,install} for kernels
  7. Test the binary
  8. If further changes are needed, repeat from step 2.
  9. Finally run make package/example/update or make target/linux/update for kernels to copy the changes back to buildroot

Further information

Back to top

doc/devel/patches.txt · Last modified: 2014/06/27 10:59 by jow

时间: 2024-08-07 04:30:21

openwrt补丁的相关文章

Openwrt 初探

最近想研究一下Openwrt,于是开始搭建openwrt环境,虽然现在没有现成的板子,但是 可以先编译起来. 看了别人的帖子,都推荐使用svn从官网下载源码, svn co svn://svn.openwrt.org/openwrt/trunk/ 但是实际测试发现它的速度太慢了,为了得到官方的源码,从github上找到了它: https://github.com/openwrt-mirror/openwrt 将它下载下来之后,要安装一些必要的包来编译它,我使用的是ubuntu12.04. sud

portal为什么选择开源路由器第三方固件 OpenWrt

现在市场上主流固件有DD-WRT ,Openwrt,tomato,为什么有选择使用openwrt 来移植wifidog做无线portal ? 关于 OpenWrt当Linksys 释放 WRT54G/GS 的源码后,网上出现了很多不同版本的 Firmware 去增强原有的功能.大多数的 Firmware 都是99%使用 Linksys的源码,只有1%是加上去的,每一种 Firmware 都是针对特定的市场而设计,这样做有2个缺点,第一个是难以集合各版本Firmware的长处,第二个是这版本距离

转:如何编译OpenWrt

原文:http://blog.chinaunix.net/uid-25890465-id-2497754.html (!文末,附加人生如戏写的编译OPENWRT的TXT内容,可直接跳至末尾,有例子) Openwrt 官方正式的发行版是已编译好了的映像文件(后缀名bin或trx.trx2),此映像文件可从Openwrt官方网站的下载页面中轻松获取到,连接地址为 OpenWrt官方网站.这些编译好的映像文件是基于默认的配置设置,且只针对受支持的平台或设备的.因此,为什么要打造一个自己的映像文件,理由

【转载】openwrt框架分析

文章出处:http://blog.csdn.net/kingvenll/article/details/27545221 这次讲讲openwrt的结构. 1. 代码上来看有几个重要目录package, target, build_root, bin, dl.... ---build_dir/host目录是建立工具链时的临时目录 ---build_dir/toolchain-<arch>*是对应硬件的工具链的目录 ---staging_dir/toolchain-<arch>* 则是

openwrt&lt;转载--openwrt框架分析 &gt;

这次讲讲openwrt的结构. 1. 代码上来看有几个重要目录package, target, build_root, bin, dl.... ---build_dir/host目录是建立工具链时的临时目录 ---build_dir/toolchain-<arch>*是对应硬件的工具链的目录 ---staging_dir/toolchain-<arch>* 则是工具链的安装位置 ---target/Linux/<platform>目录里面是各个平台(arch)的相关代码

OpenWRT开发之——目录分析与make过程

OpenWrt 目录下的 trunk 结构如下: [trunk]$ ls bin/         Config.in  feeds.conf.default  rules.mk     tmp/ BSDmakefile  dl/        include/            scripts/     toolchain/ build_dir/   docs/      LICENSE             package/     staging_dir/ tools/ config

路由器刷机常见第三方固件及管理前端种类(OpenWrt、Tomato、DD-Wrt)

目前路由器折腾刷机,除了采用各品牌的原厂固件外,第三方路由器固件,基本就是:Tomato.DD-WRT.OpenWRT三种. 基本上所有第三方路由器固件的架构上可分为前端(Frontend)和后端(Backend), 其后端基本都是OpenWRT,前端一般指图形用户接口,即GUI,主要体现为Web管理界面.而OpenWRT自身默认编译出来是不带前端的. OpenWRT的在国内常见的前端有: 1.LuCI:基于Apache License,现在主流,是自行编译的OpenWRT最佳搭配: 2.X-W

openwrt 代码框架分析

这次讲讲openwrt的结构. 1.代码上来看有几个重要目录package, target, build_root, bin, dl....---build_dir/host目录是建立工具链时的临时目录---build_dir/toolchain-是对应硬件的工具链的目录---staging_dir/toolchain- 则是工具链的安装位置---target/linux/目录里面是各个平台(arch)的相关代码---target/linux//config-3.10文件就是配置文件了---dl

玩转小米路由器先从pcDuino的OpenWrt系统开始

小米路由器发布颠覆了路由器的定义,就像当初乔布斯发布没有键盘的iphone一样.玩家们都知道小米为发烧友而生,玩家都知道小米路由器使用的深度定制的OpenWrt系统,然而对于很多玩家来说,对OpenWrt是很陌生的系统.下面我利用开源硬件pcDuino来给大家深度讲解这个系统. 在pcDuino上移植OpenWrt(一)--下载编译www\.pcduino.org/forum.php?mod=viewthread&tid=539&extra=page%3D1在pcDuino上移植OpenW