零基础OpenWRT固件编译

零基础OpenWRT固件编译

戴维营教育《物联网/智能家居开发》课程系列

1.OpenWRT项目简介

OpenWRT是一个专用于无线路由器设备的Linux发行版。支持众多的芯片方案的路由器设备,由x86到ARM,MIPS等等。

目前稳定版本是: BARRIER BREAKER (14.07)

目前开发版本是: Chaos Calmer (trunk)

详细信息参看官方网址: https://openwrt.org

2.采用OpenWRT的智能路由器

  • 极路由
  • 小米路由
  • 优酷路由
  • 迅雷路由
  • 360安全路由
  • 华为荣耀立方
  • 联想NewWiFi
  • 其他商业WiFi广告定制路由
  • …… ……

3. 采用OpenWRT的开发板

  • WRTNode
  • VoCore

4. 获取OpenWRT的源代码

我们可以去项目的官方网站获取其源代码,通过SVN或者GIT的方式,官方开发者网站:https://dev.openwrt.org/wiki/GetSource

trunk (main development tree)

  • Main repository
git clone git://git.openwrt.org/openwrt.git

14.07 branch (Barrier Breaker) - Main repository

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

当然,在我们正式开始编译前我们需要把前提依赖环境和源码准备好,

打开虚拟终端,执行如下命令:

openwrt@cheetah-desktop:~$ sudo apt-get install git build-essential libncurses5-dev gawk libssl-dev subversion;
openwrt@cheetah-desktop:~$ mkdir -p $HOME/opensource;
openwrt@cheetah-desktop:~$ cd  $HOME/opensource;
openwrt@cheetah-desktop:~/opensource$ git clone git://git.openwrt.org/openwrt.git
##上面命令会克隆远程仓库到本地,根据网络环境情况需要较长时间。

待源代码克隆下来之后,我们的源码和编译环境基本就OK了。

5. OpenWRT官方固件编译

进入源码目录下面进行软件包的更新与“安装”。

openwrt@cheetah-desktop:~/opensource$ cd openwrt;
openwrt@cheetah-desktop:~/opensource/openwrt$ ./scripts/feeds update -a;
openwrt@cheetah-desktop:~/opensource/openwrt$ ./scripts/feeds install -a;

执行上面的脚本之后就可以对我们中意的设备类型进行编译设置。如下命令进入终端下面的buildroot编译配置界面:

make menuconfig;

我们教程所采用的设备的CPU芯片是MT7620系列(MT7620A/N),下面就开始为MT7620系列的设备进行最基本的配置,步骤如下:

  1. Target System (Atheros AR7xxx/AR9xxx) --->回车进入下翻后空格选择Ralink RT288x/RT3xxx然后再回车后退,这时编译目标就是: Target System (Ralink RT288x/RT3xxx) --->了。

  2. Subtarget (RT3x5x/RT5350 based boards) --->回车进入下翻按空格选择(X) MT7620 based boards 然后回车后退,这时编译的子目标就是:Subtarget (MT7620 based boards) ---> 了。

  3. LuCI ---> 回车进去 1. Collections ---> 再回车进去再空格选择第一个<*> luci(new),然后在Exit一路后退到主菜单。

  4. 在主菜单Exit退出配置并保存。

That's All. 基本配置就是这么简单。下面开始我们人生的“第一次”路由器固件编译了,是不是很紧张阿? What Ever. 第一次总是要经历的,那就积极面对吧。

我们用下面这个命令来进行编译固件:

make V=s

就这么一个命令就会开启整个编译构建系统,全自动的去为我们编译我们需要的固件。所以的所以,这个过程将会是一个漫长的等待。如果互联网网络比较通畅,那么咱们这第一次编译的时间大约要花2~3小时。因为构建系统需要去互联网上下载各种程序库源代码,然后再逐个编译,最后集成并组建出我们需要的固件。

这段时间里,我们大可以出去湘江边溜达一圈,隔江望望毛主席,再回来咱们戴维营里看结果。

溜达回来后,编译也许结束,等结束的这个时候,我们的固件会乖乖的躺在当前目录下的bin/ramips/这个路径下.

openwrt@cheetah-desktop:~/opensource/openwrt$ ls bin/ramips/
md5sums                                                        openwrt-ramips-mt7620-rp_n53-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-ai-br100-squashfs-sysupgrade.bin         openwrt-ramips-mt7620-rt-n14u-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-ArcherC20i-squashfs-sysupgrade.bin       openwrt-ramips-mt7620-uImage.bin
openwrt-ramips-mt7620-dir-810l-squashfs-sysupgrade.bin         openwrt-ramips-mt7620-vmlinux.bin
openwrt-ramips-mt7620-e1700-squashfs-factory.bin               openwrt-ramips-mt7620-vmlinux.elf
openwrt-ramips-mt7620-e1700-squashfs-sysupgrade.bin            openwrt-ramips-mt7620-whr-1166d-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-Lenovo-y1-squashfs-sysupgrade.bin        openwrt-ramips-mt7620-whr-300hp2-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-Lenovo-y1s-squashfs-sysupgrade.bin       openwrt-ramips-mt7620-whr-600d-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-mlw221-squashfs-sysupgrade.bin           openwrt-ramips-mt7620-wmr-300-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-mlwg2-squashfs-sysupgrade.bin            openwrt-ramips-mt7620-wr8305rt-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-mt7620a_mt7530-squashfs-sysupgrade.bin   openwrt-ramips-mt7620-wrtnode-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-mt7620a_mt7610e-squashfs-sysupgrade.bin  openwrt-ramips-mt7620-wt3020-8M-squashfs-factory.bin
openwrt-ramips-mt7620-mt7620a-squashfs-sysupgrade.bin          openwrt-ramips-mt7620-wt3020-8M-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-mt7620a_v22sg-squashfs-sysupgrade.bin    openwrt-ramips-mt7620-xiaomi-miwifi-mini-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-mzk-750dhp-squashfs-sysupgrade.bin       openwrt-ramips-mt7620-zbt-wa05-squashfs-sysupgrade.bin
openwrt-ramips-mt7620-na930-squashfs-sysupgrade.bin            packages
openwrt-ramips-mt7620-root.squashfs

到了这一步,我们的MT7620系列芯片的路由器固件就都已经编译好了。我们可以选择我们合适型号的固件进行刷机了。 部分营员拿到的北京豌豆机器人小组的开发板WRTNode对应的固件文件是:openwrt-ramips-mt7620-wrtnode-squashfs-sysupgrade.bin 部分营员们拿到的铁盒子路由器是中性包装的工程产品,虽然和其他知名品牌的在外观上有差异,但是大可以不要在意这些区别。他们的配置都是差不多的。铁盒子型号WR8305RT对应的固件文件就是: openwrt-ramips-mt7620-wr8305rt-squashfs-sysupgrade.bin

设备图片如下:

WRTNode

WR8305RT


谢谢各位,欢迎交流并指正。

---- 大茶园丁@戴维营教育

http://io.diveinedu.com

http://www.diveinedu.com

https://github.com/DiveinEdu-CN

posted @ 2015-03-12 16:25  戴维营教育  阅读(10726)  评论(2编辑  收藏  举报