2024年4月5日发(作者:)

1、 安装环境

Linux系统,如果在 CentOS上操作,需安装如下依赖包:

yum install binutils bzip2 gawk gcc gcc-c++ gettext make ncurses-devel patch unzip wget zlib-devel

yum install subversion screen

如果是其他的Linux系统,请参照下表。下面是官网列出的不同的

的依赖包

Linux发布系统预先需要

Debi an Suse

Red Hat

asciidac

fedora

asciidoc

bzip2

factjar

gcc

"NU awk

gtk2. B-ncfev

intitool-update

jikes

libz-dev

make

^curses

□penssl/ssl. h

patch

^erl-EKtUtils-Na

rsync

ruby

sdcc

Unzip

wget

^□rking-sdcc

sgettext

xsltproc

zlib

as c i i do c

bimiti Is

bzip2

fas t j ar

g+

see

gavrk

libgtk2. O^dev

inf Itoo1

jikes

zliblg-^dev

infike

binutils

bzip2

fastjar

gcc-c++

gcc

gawk

binutils

bzip2

libg€j

gcc-c+f

see

gawk

gtk2-devel

Intltcol

aseiidcc

binutils

intltool

jikes

?

zlib-devel

make

libgej

gcc-C++

gcc

gawk

glk2-devel

intHotil

zlib-devel

rrrake

ncui'ses-devel

openssl-devel

patch

perl-ExtUtils^

aJceMaker

r sync

ruby

sdcc

unzip

wget

libiicui

,

ses5-dev ncurses-devel

libssl-dev

patch

libopenssl-deve1

patch

perl^xtUtils-Ma

perl -

TT

»

O

dales

ceMaker

rsync

rsync

ruby ruby

sdcc sdcc

unzip

wget

sdcc-nf

test

xsltproc

zliblg-dev

LOEip

g

t

■■

ncurses-devel

□penssl-devel

9

perl-ExtUtils-^

gkeJTaker

?

9

wget

?

Libzslt

zlib-devel

?

9 ■

zlib-devel

gettext

libxsll

zlib-devel

2、下载 OpenWRTI码

mkdir /usr/src/test cd /usr/src/test

svn co svn:///openwrt/trunk(开发版本,不稳定,不建议下载)

wget /backfire/10.03/backfire_10.03_2

(目前稳定版本,建议)

3、 检查配置环境

必须使用非root用户进行操作,添加一个普通用户。(注意:如果使用root进行操作的话,

会提示检查失败: Checking 'non-root'... failed.

[root@localhost trunk]# adduser openwrt

[root@localhost trunk]# su openwrt

为了防止文件读写权限造成问题,需要将源码

[openwrt@localhost openwrt]$ cd ~

[openwrt@localhost ~]$ cp -r /usr/src/test/trunk ./

[openwrt@localhost ~]$ cd trunk/

[openwrt@localhost trunk]$ ls

BSDmakefile LICENSE README t package scripts toolchain

Makefile docs include target tools

copy到openwet的根目录下进行所有操作。

4、 下载 feeds

Feeds是OpenWrt环境所需要的软件包套件。最重要的

'packages' 一些额外的基础路由器特性软件

'LuCI' OpenWrt 默认的 GUI

'Xwrt '另一种可选的 GUI界面

需要能够连接互联网。

feeds有:

在下载之前可以通过查看't

'文件,来检查哪些文件需要包含在环境中。

开始下载,使用:

[openwrt@localhost trunk]$ ./scripts/feeds update -a

安装feeds包,只有安装之后,在后面的make menuconfig时,才可以对相关配置进行勾选。

[openwrt@localhost trunk]$ ./scripts/feeds install -a 如果更新了 feeds的配置文件,需要添加新的软

件包用于生成系统。只需进行重复操作:

[openwrt@localhost trunk]$ ./scripts/feeds update -a

[openwrt@localhost trunk]$ ./scripts/feeds install -a

5、 进行配置

编译过程使用的交叉编译,交叉编译生成的 SDK以及image等文件的类型取决于开发环境、

我在配置 应用硬件、以及源码版本。所以要对自己的环境进行了解,才能进行正确的配置。

过程中,就遇到了这个问题, 我的硬件是brcm47xx,在第一次编译的时候,

第二次安装时,选择了 Target System (Broadcom BCM947xx/953xx[2.4]),

板子可能只支持 linux2.4 的内核。(设备型号是 Linksys Wrt54gs v3.0

选择地是Target

安装成功,我的

) (2011.05.01

每次修改代码后,

System (Broadcom BCM947xx/953xx),最后生成的包无法在 router上安装,版本不匹配。

添加:其实 Linksys Wrt54gs v3.0 是支持 Linux 2.6 版本的,Target System 选择 Broadcom

BCM947xx/953xx,编译后也是可以用的,这周末由于项目需要改某个软件,

都得重新编译一下固件,经过来回编译了十来次,都可以使用。另外。内核版本升级之后, 无线驱动

改成了 mac802.11,而非以前的wl,以为wl.o这个专门的库只在linux2.4 中才用 到。

[openwrt@localhost trunk]$ make defconfig

[openwrt@localhost trunk]$ make prereq

[openwrt@localhost trunk]$ make menuconfig

通过文本对话框进行选项配置,最主要的配置项有:

Target system (目标系统类型)

Package selection (软件包选择)

(编译系统设置) Build system settings

Kernel modules (内核模块)

[*]表示:这个包裹选中编译,并安装在 firmware中;

[M]表示:这个软件包选中编译,但并不安装在 firmware中。

在退出Menuconfig的时,会提示是否保存配置。

在仕匕我只对 target system 进行了选择;勾选了 Advanced configuration option 和 Build the

OpenWrt SDK 选项。

6、 编译

(1) 一般情况,使用一个简单的命令:

[openwrt@localhost trunk]$ make

(2) 在多核处理器系统上为提高速度,可

使用(例如用 3核处理器):

[openwrt@localhost trunk]$ make - j 3

(3) 在后台进行编译,使用空闲的 I/O资源和CPU性能,可使用(例如使用双核处理器)

[openwrt@localhost trunk]$ onice -c 3 nice -n 20 make -j 2

(4) 编译一个单独的软件包(例如在 cups软件包):

[openwrt@localhost trunk]$ make package/cups/compile V=99

(5) 如果特殊原因需要分析编译报错信息:

[openwrt@localhost trunk]$ make V=99 2>&1 |tee |grep -i error

说明:将编译的所有输出信息保存在 中,将error信息打印在屏幕上。

(6) 一个复杂指令的应用

[openwrt@localhost trunk]$ ionice -c 3 nice -n 20 make -j 2 V=99

CONFIG_DEBUG_SECTION_MISMATCH=y 2>&1 |tee |egrep -i '(warn|error)'

说明:将编译的所有输出信息保存在 中,将error和warning信息打印在屏幕上。

编译过程使用双核 CPU占用后台资源。

7、 生成镜像(Image)位置

新生成的镜像会默认放在新建的一个

[openwrt@localhost trunk]$ Is bin/*

将编译好的镜像做个备份,例如备份到

[openwrt@localhost trunk]$ cp bin /

bin目录下。例如

/bin/brcm-2.4/packages

/目录下:

8、 清理工作

建议现在清理编译产生的文件, 以免下次编译时造成冲突,

替换),执行 make clean

注意:在执行clean命令,确保已经将编译好的

目录。

[openwrt@localhost trunk]$ make clean

除了清除生成的目录,还想清除交叉编译工具(以及工具链目录)

[openwrt@localhost trunk]$ make dirclean

清除所有相关的东西,包括下载的软件包,配置文件,

[openwrt@localhost trunk]$ make distclean

对于更新feeds后出现的错误:

ERROR:please fix package/feeds/packages/mc/Makefile

句进行系统的清理

等类似的问题,需要执行这条语

feed内容等:(不建议使用)

image进行了备份。清理工作会清楚bin

(文件如果存在的话, 将不会被

9、 安装 OpenWrt

找到对应的固件,进行固件升级。网上方法很多,这里不再赘述。

后续会推出在 OpenWrt上的开发文档:)