Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1117
  • 博文数量: 1
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2016-09-24 10:42
文章分类
文章存档

2016年(1)

我的朋友
最近访客

分类: LINUX

2016-09-24 10:46:08

 

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发布系统预先需要的依赖包:


2、  下载OpenWRT源码

mkdir /usr/src/test

cd /usr/src/test

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

wget (目前稳定版本,建议)


3、  检查配置环境

必须使用非root用户进行操作,添加一个普通用户。(注意:如果使用root进行操作的话,会提示检查失败:Checking 'non-root'... failed.)

[root@localhost trunk]# adduser openwrt  

[root@localhost trunk]# su openwrt

为了防止文件读写权限造成问题,需要将源码copy到openwet的根目录下进行所有操作。

[openwrt@localhost openwrt]$ cd ~

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

[openwrt@localhost ~]$ cd trunk/

[openwrt@localhost trunk]$ ls

BSDmakefile  LICENSE   README  feeds.conf.default  package   scripts  toolchain

Config.in    Makefile  docs    include             rules.mk  target   tools


4、  下载feeds

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

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

‘LuCI’OpenWrt默认的GUI

‘Xwrt’另一种可选的GUI界面

需要能够连接互联网。

在下载之前可以通过查看’feeds.conf.default’文件,来检查哪些文件需要包含在环境中。

开始下载,使用:

[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),最后生成的包无法在router上安装,版本不匹配。第二次安装时,选择了Target System (Broadcom BCM947xx/953xx[2.4]),安装成功,我的板子可能只支持linux2.4的内核。(设备型号是Linksys Wrt54gs v3.0 (2011.05.01添加:其实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 build.log |grep -i error

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

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

[openwrt@localhost trunk]$ ionice -c 3 nice -n 20 make -j 2 V=99 CONFIG_DEBUG_SECTION_MISMATCH=y 2>&1 \|tee build.log |egrep -i '(warn|error)'

说明:将编译的所有输出信息保存在build.log中,将error和warning信息打印在屏幕上。编译过程使用双核CPU,占用后台资源。


7、  生成镜像(Image)位置

新生成的镜像会默认放在新建的一个bin目录下。例如:/bin/brcm-2.4/packages

[openwrt@localhost trunk]$ ls bin/*

将编译好的镜像做个备份,例如备份到/目录下:

[openwrt@localhost trunk]$ cp bin /


8、  清理工作

建议现在清理编译产生的文件,以免下次编译时造成冲突,(文件如果存在的话,将不会被替换),执行make clean

注意:在执行clean命令,确保已经将编译好的image进行了备份。清理工作会清楚bin目录。

[openwrt@localhost trunk]$ make clean  

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

[openwrt@localhost trunk]$ make dirclean

清除所有相关的东西,包括下载的软件包,配置文件,feed内容等:(不建议使用)

[openwrt@localhost trunk]$ make distclean

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

ERROR:please fix package/feeds/packages/mc/Makefile 等类似的问题,需要执行这条语句进行系统的清理

 

9、  安装OpenWrt

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

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

博主网址:

http://hi.baidu.com/gouoooo/blog/category/%C7%B6%C8%EB%CA%BD%CF%B5%C1%D0
阅读(198) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~