开始编译着手编译OpenWrt啦

OpenWrt 杨博, 卫 765次浏览 0个评论

          手上有个TL-WR703N(改8M的Flash,64M的RAM)TL-WR720N(改16M的Flash,64M的RAM)和Dir-505。自己在调教OpenWrt的时候总结了一些心得,借霜之哀伤的小站记下来跟大家分享,自己能力也有限,欢迎一起交流。

FPRD9RUHA4MKB7R.MEDIUMtl-wr720n_05DSC_7007

 

 

 

 

 

 

玩转OP要从会编译开始,首先说一下编译过程

一、编译前的准备

首先你需要运行Linux的实体机或虚拟机,不低于20G的磁盘剩余空间,有一定Linux操作经验,我的教程会写的比较简单,只是提供一个思路。

认真看以下注意事项

1. 请使用一个非root用户来完成这些工作!
2. 这里的所有命令都在OpenWrt编译系统的根目录下运行(例如~/openwrt/trunk/
3. 编译系统的绝对路径中不能含有空格!
4. 如果你使用root用户下载了源码,请把你下载来的源码的所有者更改为一个非root用户。(sudo chown -R user:user /openwrt/)

然后我们需要安装编译器等等编译时需要用到的依赖

Debian系

sudo apt-get update
sudo apt-get install git-core build-essential libssl-dev libncurses5-dev unzip subversion gawk flex libssl-dev sdcc-nf libxml-parser-perl mercurial bzr ecj cvs quilt xsltproc

CentOS系

sudp yum update
sudo yum install subversion binutils bzip2 gcc gcc-c++ gawk gettext flex ncurses-devel zlib-devel make patch unzip perl-ExtUtils-MakeMaker  glibc glibc-devel glibc-static quilt ncurses sed sdcc intltool sharutils bison wget git-core openssl-devel xz libstdc++ ncurses-compat-libs nss-softokn-freebl zlib-static

不出意外光安装以上这些是不够的,后面会有提到

 

通过git来下载OpenWrt bleeding edge(trunk版本)源码:

git clone git://git.openwrt.org/openwrt.git

这将会创建’openwrt’这个目录。这个目录将会是OpenWrt的编译主目录。
OpenWrt的交叉编译工具链也已经被包含在内。

 

下载并安装所有可用的”feeds”(参见OpenWrt Feeds以获取更多选择):

cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a

下载OpenWrt官方维护的软件

 

运行下面的命令让OpenWrt编译系统检查你的编译环境中缺失的软件包:

make defconfig
make prereq

如果你有缺少的软件,在执行make defconfig时是通不过的,需要安装缺失软件。

二、开始定制固件并编译

make menuconfig

Screenshot at 2016-06-17 16:37:22

make menuconfig之后出现以上界面那么恭喜你离成功不远了,接着就可以选择对应的路由器,简单地定制你的固件了。大家自己摸索,参见:build
记得保存你的配置为.config,因为编译的时候会按照.config文件来编译.

一切就绪下面就差编译了

make V=99

以上命令会保存一份详尽的编译输出,并只在屏幕上输出错误,因为第一次编译是需要大半天的,而且肯定会报错(不要方,下面会提供解决方案),所以我们需要看看究竟哪里有错误。

另外,强烈不建议用make -j V=99多线程编译,极容易司机,而且会出现不明的编译错误。

三、编译结束

结束后生成的固件在。./openwrt/bin/目录对应架构里面,可以开始Upgrade Firmware了。

 四、一些错误的分析

1.必须使用非root账户编译

报错如下

root@Openwrt-Compiled:/avalon/openwrt# make menuconfig
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'getopt'... ok.
Checking 'fileutils'... ok.
Checking 'working-gcc'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'zlib'... ok.
Checking 'gawk'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'patch'... ok.
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'wget'... ok.
Checking 'git'... ok.
Checking 'gnutar'... ok.
Checking 'svn'... ok.
Checking 'gnu-find'... ok.
Checking 'getopt-extended'... ok.
Checking 'non-root'... failed.

Build dependency: Please do not compile as root.

Prerequisite check failed. Use FORCE=1 to override.
make: *** [tmp/.prereq-build] Error 1

方案一(不推荐):强行跳过

make menuconfig FORCE=1

方案二:vim注释掉这个文件[include/prepreq-build.mk]

ClipCapIt-130802-175752

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.某一个软件的源码下载失败,不能正确get

    solving polarssl.org (polarssl.org)... 79.170.91.36
    Connecting to polarssl.org (polarssl.org)|79.170.91.36|:443... connected.
    HTTP request sent, awaiting response... 301 Moved Permanently
    Location: https://tls.mbed.org/download/mbedtls-1.3.11-gpl.tgz [following]
    --2015-06-11 01:39:41-- https://tls.mbed.org/download/mbedtls-1.3.11-gpl.tgz
    Resolving tls.mbed.org (tls.mbed.org)... 79.170.91.36
    Connecting to tls.mbed.org (tls.mbed.org)|79.170.91.36|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1731809 (1.7M) [application/x-gzip]
    Saving to: 'STDOUT'

    20% [=======> ] 360,408 17.7KB/s in 21s

    2015-06-11 01:40:06 (17.1 KB/s) - Connection closed at byte 360408. Retrying.

    --2015-06-11 01:40:07-- (try: 2) https://tls.mbed.org/download/mbedtls-1.3.11-gpl.tgz
    Connecting to tls.mbed.org (tls.mbed.org)|79.170.91.36|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1731809 (1.7M) [application/x-gzip]
    Saving to: 'STDOUT'

    32% [===========> ] 555,968 30.5KB/s in 22s

    2015-06-11 01:40:32 (24.6 KB/s) - Connection closed at byte 555968. Retrying.

    --2015-06-11 01:40:34-- (try: 3) https://tls.mbed.org/download/mbedtls-1.3.11-gpl.tgz
    Connecting to tls.mbed.org (tls.mbed.org)|79.170.91.36|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1731809 (1.7M) [application/x-gzip]
    Saving to: 'STDOUT'

    32% [===========> ] 555,968 26.6KB/s in 22s

    2015-06-11 01:40:58 (24.6 KB/s) - Connection closed at byte 555968. Retrying.

    --2015-06-11 01:41:01-- (try: 4) https://tls.mbed.org/download/mbedtls-1.3.11-gpl.tgz
    Connecting to tls.mbed.org (tls.mbed.org)|79.170.91.36|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1731809 (1.7M) [application/x-gzip]
    Saving to: 'STDOUT'

    30% [==========> ] 524,224 23.9KB/s in 22s

    2015-06-11 01:41:24 (23.0 KB/s) - Connection closed at byte 555968. Retrying.

    --2015-06-11 01:41:28-- (try: 5) https://tls.mbed.org/download/mbedtls-1.3.11-gpl.tgz
    Connecting to tls.mbed.org (tls.mbed.org)|79.170.91.36|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1731809 (1.7M) [application/x-gzip]
    Saving to: 'STDOUT'

    26% [=========> ] 457,680 21.7KB/s in 24s

    2015-06-11 01:41:54 (18.5 KB/s) - Connection closed at byte 555968. Giving up.

    Download failed.
    --2015-06-11 01:41:54-- http://mirror2.openwrt.org/sources/mbedtls-1.3.11-gpl.tgz
    Resolving mirror2.openwrt.org (mirror2.openwrt.org)... 46.4.11.11
    Connecting to mirror2.openwrt.org (mirror2.openwrt.org)|46.4.11.11|:80... connected.
    HTTP request sent, awaiting response... 404 Not Found
    2015-06-11 01:41:55 ERROR 404: Not Found.

    Download failed.
    --2015-06-11 01:41:55-- http://downloads.openwrt.org/sources/mbedtls-1.3.11-gpl.tgz
    Resolving downloads.openwrt.org (downloads.openwrt.org)... 78.24.191.177
    Connecting to downloads.openwrt.org (downloads.openwrt.org)|78.24.191.177|:80... connected.
    HTTP request sent, awaiting response... 404 Not Found
    2015-06-11 01:41:56 ERROR 404: Not Found.

    Download failed.
    No more mirrors to try - giving up.
    make[3]: *** [/home/hand1234/openwrt/trunk/dl/mbedtls-1.3.11-gpl.tgz] Error 2
    make[3]: Leaving directory /home/hand1234/openwrt/trunk/package/libs/polarssl'
    make[2]: *** [package/libs/polarssl/compile] Error 2
    make[2]: Leaving directory/home/hand1234/openwrt/trunk'
    make[1]: *** [/home/hand1234/openwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
    make[1]: Leaving directory `/home/hand1234/openwrt/trunk'
    make: *** [world] 错误 2

解决方案:如果是网络不稳定,可以重新make一下看看能不能解决,如果是死链,那只能自己从网上下载这个包,放在dl文件下,这样就可以了。

3.内存不足

当程序运行到某处报错

i686-linux-gnu-g++: internal compiler error: Killed (program cc1plus)

解决方案:内存不足,编译器干不下去拉,加SWAP吧。

4.编译固件大小超过路由器Flash大小

编译通过,但是没有在./openwrt/bin/找到固件,往上翻编译输出提示,发现类似

[mktplinkfw] kernel length aligned to 914864
[mktplinkfw] *** error: images are too big
make[3]: [install] Error 255 (ignored)

解决方案:适当减少软件,或者硬改Flash吧。

5.其他

除此之外,磁盘空间不足,在编译时修改源码,错误修改源码或者上次编译的缓存与新的源码有冲突等等都可能造成各种各样的错误。

 

写在后面

这只是开始为以后我们定制OP固件做一个铺垫,接下来才是重头戏


本文版权:霜之哀伤 转载请注明开始编译着手编译OpenWrt啦
喜欢 (3)or分享 (0)
杨博, 卫
关于作者:
喜欢折腾路由器,懂一点Linux,最近正在学习树莓派...
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址