openwrt开发

零基础openwrt固件编译、移植

http://edu.csdn.net/course/detail/1390/21642    

参考:http://blog.csdn.net/fyh2003/article/details/44564219

     http://blog.csdn.net/lyykjen0816/article/details/50524138

   http://www.cnblogs.com/diveinedu/p/4332783.html(戴维营 博客园)

1.简介

  openWRT是一个专用于无线路由器设备的嵌入式Linux发行版,支持众多的芯片方案的路由器设备,由X86到ARM,MIPS等等。openwrt具有强大的扩展性。与其他许多路由器的发行版不同的是,openWRT是一个从零开始编写的,功能齐全的、容易修改的路由器操作系统。意味着我们可以使用我们想要的功能而不加进其他的累赘而支持这些功能工作的linuxkernel又远比绝大多数发行版来的新。
  openWRT提供了一个完全可写文件系统及软件包管理,而不是试图建立一个单一的、静态的固件。这将我们从路由器制造商选定的程序功能、提供的配置的桎梏中解放出来,并允许您使用包来定制嵌入式装置,使之适用于任何应用。
  对于研发人员,它提供了一个框架直接用来建立应用程序,而无需创建一个完整的固件镜像并为它专门定制一个发行版;
  对于用户来说,这意味着完全定制的自由,这使得我们能用卖方难以预料的方式使用嵌入式设备。
openWRT并未打算发布现成的可以直接加载到你的嵌入式设备的固件。相反,该框架允许我们建立适合自己的特殊需求的一个固件。
目前稳定版本:BARRIER BREAKER(14.07)
目前开发版本:Chaos Calmer(trunk)
详情更新请看官网。
2.采用openWRT的智能路由器:
极路由;小米路由器;优酷路由;迅雷路由;360安全路由;华为荣耀立方;联想NewWiFi;其他商业WiFi广告定制路由。。。。。。

3.采用openWRT的开发板:
WRTNode;
VoCore

4.从openWRT官网:https://openwrt.org/ 下载获取源码:
[root@localhost openwrt]# git clone git://git.openwrt.org/openwrt.git //2.下载OpenWrt源码并编译
Initialized empty Git repository in /openwrt/openwrt/.git/
remote: Counting objects: 343902, done.
remote: Compressing objects: 100% (94096/94096), done.
remote: Total 343902 (delta 237354), reused 340863 (delta 235080)
Receiving objects: 100% (343902/343902), 117.82 MiB | 76 KiB/s, done.
Resolving deltas: 100% (237354/237354), done.
OpenWrt源码分两种,一种是最新但不是最稳定的Trunk开发版,一种是最稳定的Backfire版
[root@localhost openwrt]# ls
openwrt
[root@localhost openwrt]# ls openwrt/
BSDmakefile docs LICENSE README target
config feeds.conf.default Makefile rules.mk toolchain
Config.in include package scripts tools
然后装上各种依赖关系包:
[root@localhost ~]# sudo yum install -y gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversi-dev ncurses-term zliblg-dev   //1.搭建编译环境

//注意:
yum install zlib-static 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-lib sed sdcc intltool sharutils bison wget git-core openssl-devel xz -y

5.openwrt官方固件编译  //2.编译及配置
进入源码目录下面进行软件包的更新与“安装”
更新扩展,安装扩展:
[root@localhost openwrt]# ./scripts/feeds update -a //更新最新的包定义
[root@localhost openwrt]# ./scripts/feeds install -a //安装所有的包
//feeds命令将安装扩展代码包编译选项,如果不运行该命令,在menuconfig配置时将没有选择这些扩展包的机会。
注:如果不是刚下载的源码,为保持代码为最新状态,应定期运行svn update命令更新源码。
测试编译环境:
[root@localhost openwrt]# make defconfig //检查所以需要的编译工具是否齐背,并生成默认的编译配置文件.config

//工作项目说明:

  我们这里原始的.config是王哥配置好的,可以先make编译成功;完了再menuconfig 选配自己需要的配置选项后make编译(自动修改.config文件)成功,查看openwrt配置网页。
[root@localhost openwrt]# make menuconfig //开始编译自己的固件了。进入定制界面:

  
如果一切正常,会出现一个配置菜单,可以选择要编译的固件平台(芯片类型)、型号,还能选择固件中要添加的功能和组件,配置好后保存并退出菜单即可。
//[Y]:将该模块编译进内核;
//[M]:将作为模块来编译;
//[N]:将不编译该模块;

遇到的问题解决(1):
比如:zlib静态库,此依赖比较麻烦需要上网自己下载
wget http://zlib.net/zlib-1.2.8.tar.gz (由于此源码还在不断更新,因此版本号可能有些出入,当出现404页面找不到时可以通过浏览器登录zlib.net/ 查看当前的版本号)
下载完成后进行解压安装:
#tar -zxvf zlib-1.2.8.tar.gz #解压
#cd zlib-1.2.8
#./config
#make
#make install

6.
[root@localhost openwrt]# make V=99
make是编译命令,V=99表示输出debug信息,V一定要大写,如果要让CPU全速编译,就加上 -j 参数,第一次编译最好不带-j参数。
编译过程保持联网(会从网上下载一些源码包),所以断网可能造成编译中断,编译所需时间与电脑CPU及网络环境有很大关系,第一次编译时间较久,快则半小时长则2、3个小时,之后的编译所需时间较短。编译完成后会在源码文件目录出现bin文件夹(如trunk/bin/XXXX),如果你手里的路由是原版固件需要刷OpenWrt需要选用XXX-factory.bin固件,如果路由已经刷了OpenWrt,选用升级固件XXXX-sysupgrade.bin升级用的,在升级界面升级即可。进到文件夹找到你需要的固件传出(通过邮箱、网盘、U盘等),开始刷机吧。

遇到的问题解决(2):
checking whether mknod can create fifo without root privileges... configure: error: in `/openwrt/openwrt/build_dir/host/tar-1.28':
configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
See `config.log' for more details
make[3]: *** [/openwrt/openwrt/build_dir/host/tar-1.28/.configured] Error 1
make[3]: Leaving directory `/openwrt/openwrt/tools/tar'
make[2]: *** [tools/tar/compile] Error 2
make[2]: Leaving directory `/openwrt/openwrt'
make[1]: *** [/openwrt/openwrt/staging_dir/target-mips_34kc_musl-1.1.14/stamp/.tools_install_yynyynynynyyyyyyynyyyyyyyyyyyyynyyyyynnyynynyyyynnnyy] Error 2
make[1]: Leaving directory `/openwrt/openwrt'
make: *** [world] 错误 2
[root@localhost openwrt]# export FORCE_UNSAFE_CONFIGURE=1&& make V=99 //have a try!

 

遇到的问题解决(3):
。。。。。。
SHELL= flock /openwrt/openwrt/tmp/.cmake-3.5.1.tar.gz.flock -c ' /openwrt/openwrt/scripts/download.pl "/openwrt/openwrt/dl" "cmake-3.5.1.tar.gz" "ca051f4a66375c89d1a524e726da0296" "" "https://cmake.org/files/v3.5/" "https://fossies.org/linux/misc/"'
--2017-10-20 09:54:15-- https://cmake.org/files/v3.5/cmake-3.5.1.tar.gz
Resolving cmake.org... 66.194.253.19
Connecting to cmake.org|66.194.253.19|:443... connected.
Unable to establish SSL connection.
Download failed.

[root@localhost linux-3.5]# yum install cmake //ok

 

遇到的问题解决(4):
---------------------------------------------
gmake[4]: Entering directory `/openwrt/openwrt/build_dir/host/cmake-3.5.1/Bootstrap.cmk'
gmake[4]: `cmake' is up to date.
gmake[4]: Leaving directory `/openwrt/openwrt/build_dir/host/cmake-3.5.1/Bootstrap.cmk'
/openwrt/openwrt/build_dir/host/cmake-3.5.1/Bootstrap.cmk/cmake: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /openwrt/openwrt/build_dir/host/cmake-3.5.1/Bootstrap.cmk/cmake)
---------------------------------------------
Error when bootstrapping CMake:
Problem while running initial CMake
---------------------------------------------
make[3]: *** [/openwrt/openwrt/build_dir/host/cmake-3.5.1/.configured] Error 11
make[3]: Leaving directory `/openwrt/openwrt/tools/cmake'
make[2]: *** [tools/cmake/compile] Error 2
make[2]: Leaving directory `/openwrt/openwrt'
make[1]: *** [/openwrt/openwrt/staging_dir/target-mips_34kc_musl-1.1.14/stamp/.tools_install_yynyynynynyyyyyyynyyyyyyyyyyyyynyyyyynnyynynyyyynnnyy] Error 2
make[1]: Leaving directory `/openwrt/openwrt'
make: *** [world] 错误 2

//原因是没有GLIBCXX_3.4.15版本,或是更高的版本!
输入命令查询一下结果:
[root@localhost openwrt]# strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

我们看到当前GCC版本中的确没有GLIBCXX_3.4.15。
下载新版本,地址:http://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/libstdc++6_4.7.2-5_i386.deb
64位系统:
http://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/libstdc++6_4.7.2-5_amd64.deb

[root@localhost tools]# pwd
/openwrt/tools
[root@localhost tools]# ls
libstdc++6_4.7.2-5_amd64.deb zlib-1.2.8 zlib-1.2.8.tar.gz
[root@localhost tools]# ar -x libstdc++6_4.7.2-5_amd64.deb //解压:
[root@localhost tools]# ls
control.tar.gz debian-binary zlib-1.2.8
data.tar.gz libstdc++6_4.7.2-5_amd64.deb zlib-1.2.8.tar.gz
[root@localhost tools]# tar -xvf data.tar.gz //解压:
./
./usr/
./usr/share/
./usr/share/doc/
./usr/lib/
./usr/lib/x86_64-linux-gnu/
./usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
./usr/share/doc/libstdc++6
./usr/lib/x86_64-linux-gnu/libstdc++.so.6
[root@localhost tools]# ls
control.tar.gz debian-binary usr zlib-1.2.8.tar.gz
data.tar.gz libstdc++6_4.7.2-5_amd64.deb zlib-1.2.8
[root@localhost tools]# cd usr/lib/
[root@localhost lib]# ls
x86_64-linux-gnu
[root@localhost lib]# cd x86_64-linux-gnu/
[root@localhost x86_64-linux-gnu]# ls
libstdc++.so.6 libstdc++.so.6.0.17
[root@localhost x86_64-linux-gnu]# cp libstdc++.so.6.0.17 /usr/lib //注意/lib 和 /lib64区别
[root@localhost x86_64-linux-gnu]# cd /usr/lib
[root@localhost lib]# rm libstdc++.so.6
rm:是否删除符号链接 "libstdc++.so.6"?y
[root@localhost lib]# ln libstdc++.so.6.0.17 libstdc++.so.6

重新建立软连接,我们再输入命令查询一下结果:
[root@localhost lib]# strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15 //已经安装好GLIBCXX_3.4.15啦!
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_DEBUG_MESSAGE_LENGTH

 

遇到的问题解决(5):
Yum中实现与apt-get install build-essential功能类似的命令:

在Ubuntu中安装完系统后,可以直接使用apt-get install build-essential命令安装常用的开发编译工具包。在诸如CentOS这样的使用Yum包管理的系统中,其实也有类似的实现方法。解决方案是使用如下命令:

yum groupinstall "Development Tools"
//[root@localhost openwrt]# yum groupinstall "Development Tools"

遇到的问题解决(6):
centos 系统桌面上的图标都不见了!
解答:
将/etc/sysconfig/i18n还原还是出现这样的问题,最后重启了好多次,实在是不行。
最好将i18n里的代码改成如下:
LANG="zh_CN.UTF-8"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
SYSFONT="latarcyrheb-sun16"
然后 保存重启,页面的图标出现了,只是都变成了中文

openwrt编译前基本配置-2
openwrt编译与结果说明-3

Signing package index...
make[2]: Leaving directory `/openwrt'
make[1]: Leaving directory `/openwrt'
[root@crmn openwrt]# ls bin/ramips/
md5sums
openwrt-ramips-mt7621-dir-860l-b1-squashfs-factory.bin
openwrt-ramips-mt7621-dir-860l-b1-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-firewrt-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-mt7621-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-oolite-v8-16MB-15.05-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashfs-sysupgrade.bin //
openwrt-ramips-mt7621-oolite-v8-8MB-15.05-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-pbr-m1-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-re6500-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-wsr-1166-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-wsr-600-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-zbt-wg2626-squashfs-sysupgrade.bin
packages
sha256sums
[root@crmn openwrt]#

 

//刷机步骤:

  网线链接路由器和主机,按住rest启动板子 然后打开192.168.1.1 刷到OS那一项。
主机IP改为:192.168.1.95 //试验完后改回来192.168.10.95
cmd ping 192.168.1.1

openwrt命令行升级固件-4 

  

 

 

 

WRTNode/OpenWRT 恢复出厂设置:
方式一:
openwrt后台web界面操作。
连接wifi后,输入网页密码:192.168.8.1登录到后台管理的登陆界面,systerm/backup/flash operations

方式二:
SSH登录到路由器系统下操作。
连接wifi后,ping 192.168.8.1
ssh root@192.168.8.1登录到命令行端,输入密码
打开网页 systerm/administration 设置密码,保存应用。
回到命令行端,重新ssh root@192.168.8.1,输入刚才设置的密码后成功登录openwrt系统

ls
touch test.txt //测试看是否恢复重置!
firstboot //初始化擦除,出厂设置!
重启:reboot;exit //随时看网络wifi信号,重新手动连接。

rm ~/.ssh/known_hosts
ssh root@192.168.8.1重新登录;尝试ping 192.168.8.1
打开网页,可以无密码登录了,意味着恢复出厂设置了!
(也可以重新设置密码,保存应用。回到命令行端,
然后重新ssh root@192.168.8.1,输入刚才设置的密码后成功登录openwrt系统)

root@OpenWrt:~# passwd root
Changing password for root
New password:
Bad password: too short
Retype password:
Password for root changed by root
root@OpenWrt:~# exit
Connection closed by foreign host.
[root@crmn ~]# telnet 192.168.1.1 //未设置密码直接登录
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
Login failed.
Connection closed by foreign host.
[root@crmn ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=0.882 ms
[root@crmn ~]# ssh root@192.168.1.1 //设置密码的登录方式
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is b6:81:15:ca:97:14:16:79:53:07:b5:a7:1d:a0:31:8c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
root@192.168.1.1's password:


BusyBox v1.23.2 (2017-10-25 16:36:40 CST) built-in shell (ash)

_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
CHAOS CALMER (Chaos Calmer, unknown)
-----------------------------------------------------
* 1 1/2 oz Gin Shake with a glassful
* 1/4 oz Triple Sec of broken ice and pour
* 3/4 oz Lime Juice unstrained into a goblet.
* 1 1/2 oz Orange Juice
* 1 tsp. Grenadine Syrup
-----------------------------------------------------

//刷机:
[root@crmn openwrt]# scp bin/ramips/openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashfs-sysupgrade.bin root@192.168.1.1:/tmp/
root@192.168.1.1's password:
openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashf 100% 4864KB 2.4MB/s 00:02
[root@crmn openwrt]# ssh root@192.168.1.1
root@192.168.1.1's password:


BusyBox v1.23.2 (2017-10-25 16:36:40 CST) built-in shell (ash)

_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
CHAOS CALMER (Chaos Calmer, unknown)
-----------------------------------------------------
* 1 1/2 oz Gin Shake with a glassful
* 1/4 oz Triple Sec of broken ice and pour
* 3/4 oz Lime Juice unstrained into a goblet.
* 1 1/2 oz Orange Juice
* 1 tsp. Grenadine Syrup
-----------------------------------------------------
root@OpenWrt:~# ls /tmp/
TZ
dhcp.leases
dnsmasq.d
etc
hosts
lib
lock
log
luci-indexcache
luci-modulecache
openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashfs-sysupgrade.bin //
root@OpenWrt:~# cd /tmp/
root@OpenWrt:/tmp# sysupgrade -n openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashfs-
sysupgrade.bin
Sysupgrade is not yet supported on oolite-v8-32mb.
Image check 'platform_check_image' failed. //失败!

 



WRTNode/OpenWRT路由后台管理登录
由于各种原因需要在后台进行一些设置:
(1)插电,开机WRTNode或者就、开机路由器;
(2)等待WRTNode或者路由器开机结束后通过无线或者有线链接到板子或者路由器;
(3)打开网络设置,此步骤根据使用的不同操作系统而不同,查看到你所链接路由器或者WRTNode板子的网卡获取的IP地址;
(4)打开浏览器,找到地址栏,输入上一步查看到的IP地址,回车,将会打开后台管理登陆界面。

 

------------------------------------------------------------------------

F:\openWRT\openwrt_bin\20180102_wang_ok
openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashfs-sysupgrade.bin

20180101
[root@crmn tau_openwrt]# pwd
/tau_openwrt
[root@crmn tau_openwrt]# du -sh openwrt-15.05-release/
975M openwrt-15.05-release/
[root@crmn tau_openwrt]# svn checkout svn://192.168.10.107/tau/oolite/openwrt-15.05-release^C

[root@crmn openwrt-15.05-release]# yum install zlib-static 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-lib sed sdcc intltool sharutils bison wget git-core openssl-devel xz -y

[root@crmn openwrt-15.05-release]# ./scripts/feeds update -a
[root@crmn openwrt-15.05-release]# ./scripts/feeds install -a

[root@crmn openwrt-15.05-release]# make defconfig
[root@crmn openwrt-15.05-release]# make V=99


[root@crmn openwrt-15.05-release]# ls bin/ramips/
md5sums
openwrt-ramips-mt7621-dir-860l-b1-squashfs-factory.bin
openwrt-ramips-mt7621-dir-860l-b1-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-firewrt-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-mt7621-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-oolite-v8-16MB-15.05-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-oolite-v8-32MB-15.05-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-oolite-v8-8MB-15.05-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-pbr-m1-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-re6500-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-wsr-1166-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-wsr-600-squashfs-sysupgrade.bin
openwrt-ramips-mt7621-zbt-wg2626-squashfs-sysupgrade.bin
packages
sha256sums
You have new mail in /var/spool/mail/root

posted @ 2017-10-20 17:40  bkycrmn  阅读(1133)  评论(0)    收藏  举报