Openwrt中文手册

维基教科书,自由的教学读本

OpenWRT中文手册

引言[编辑]

本文是OpenWRT源码手册的中文译本。可以通过版本控制工具SVN或者GIT来得到OpenWRT的源码,命令如下: svn co svn://svn.openwrt.org/openwrt/branches/8.09 git://nbd.name/openwrt.git 下载完源码后,需要进入docs目录编译生成pdfhtml格式的英文文档。命令如下:
# cd docs
# make
当前目录下的openwrt.pdf和openwrt.html即为生成的最终文件。

第一章 路由器设置简介[编辑]

1.1 快速开始[编辑]

1.1.1 安装[编辑]

1.1.2 初始化设置[编辑]

1.1.3 安全模式[编辑]

1.2 配置OpenWrt[编辑]

1.2.1 网络[编辑]

第二章 开发指南[编辑]

2.1 系统结构[编辑]

2.1.1 构造镜像[编辑]

OpenWrt选择了另一种方式来生成固件:下载,打补丁,编译,一切从零开始,即使交叉编译链也是如此。

下载OpenWrt[编辑]

本文仅针对OpenWrt的Kamikaze分支编写,可以使用如下subversion命令下载代码:
$ svn checkout svn://svn.openwrt.org/openwrt/trunk kamikaze
另外,还有一个trac显示界面[1],可以用它来浏览通过svn进行的提交和代码。

目录结构[编辑]

有四个关键的顶层目录:

  • tools
  • toolchain
  • package
  • target

toolstoolchain包含了一些通用命令,用来生成固件、编译器、和C库。生成结果会储存在以下三个目录下:build dir/host是一个临时目录,用来储存不依赖于目标平台的工具,build dir/toolchain-<arch>*用来储存依赖于指定平台的编译链,staging dir/toolchain-<arch>*是编译链的最终安装位置。通常你不需要改动编译链目录下的任何东西,unless you intend to add a new version of one of the components above.

  • build dir/host
  • build dir/toolchain-<arch>*

package——包。在OpenWrt固件中,几乎所有东西都是.ipk,这样就可以很方便的安装和卸载。注意:这些包不是在主分支中维护的,但是可以使用package feeds系统通过subversion来获取他们。
$ ./scripts/feeds update
这些包能够扩展基本系统的功能,只需要将他们链接进入主干。之后,这些包将会显示在配置菜单中。对于kamikaze,你可以使用这样的命令:
$ ./scripts/feeds search nmap
Search results in feed 'packages':
nmap Network exploration and/or security auditing utility
$ ./scripts/feeds install nmap
如果想包含所有的包,可以使用如下命令:
$ make package/symlinks
目标系统指嵌入式设备,针对不同的平台有不同的特性。针对这些特性,"target/linux"目录下按照平台<arch>进行目录划分,里面包括了针对标准内核的补丁,特殊配置等。There's also the "target/image" directory which describes how to package a firmware for a specific platform.
target and package两部分都需要"build dir/<arch>"作为编译的临时目录。另外,编译链,目标平台,包要下载的东西都放在dl目录下。

  • build dir/<arch>
  • dl

2.3 使用Openwrt[编辑]

以下的段落将会介绍一些技巧,可以提高日常工作的效率。

2.3.1 编译/重编译组件[编辑]

buildroot可以很方便的重编译整个系统,也可以只编译某个部分,比如工具链、内核模块、内核和软件包等。
如果你做了一些修改,然后想重编译工具链,可以执行如下命令:
make toolchain/{clean,compile,install}
它将会clean, compile and install工具链,将会显示如下:
make[1] toolchain/clean
make[2] -C toolchain/kernel-headers clean
make[2] -C toolchain/binutils clean
make[2] -C toolchain/gcc clean
make[2] -C toolchain/uClibc clean (glibc or eglibc when chosen)
当然,你也可以分开编译工具链的几个部分(binutils, kernel-headers gcc, C library)。
可以用同样的方法编译软件包。
make package/busybox/{clean,compile,install}

will clean, compile and install buysbox (if selected to be installed on the final rootfs).

Supposing that you made changes to the Linux kernel, but do not want to recompile everything, you can recompile only the kernel modules by issuing:

make target/linux/compile To recompile the static part of the kernel use the following command: make target/linux/install

2.3.2 使用OpenWrt内部的quilt[编辑]

OpenWrt integrates quilt in order to ease the package, kernel and toolchain patches maintenance when migrating over new versions of the software.

Quilt intends to replace an old workflow, where you would download the new source file, create an original copy of it, an a working copy, then try to apply by hand old patches and resolve conflicts manually. Additionnaly, using quilt allows you to update and fold patches into other patches easily.

Quilt is used by default to apply Linux kernel patches, but not for the other components (toolchain and packages).

附件[编辑]

OpenWrt英文手册