Openwrt 初探
最近想研究一下Openwrt,于是开始搭建openwrt环境,虽然现在没有现成的板子,但是
可以先编译起来。
openwrt的特点是基于下载 -> patch -> 编译 的一个工作模式,openwrt整个包一开始下载下来也不是很大,因为里面
基本上没有源码,要在编译的时候下载。
看了别人的帖子,都推荐使用svn从官网下载源码,
svn co svn://svn.openwrt.org/openwrt/trunk/
但是实际测试发现它的速度太慢了,为了得到官方的源码,从github上找到了它:
https://github.com/openwrt-mirror/openwrt
将它下载下来之后,要安装一些必要的包来编译它,我使用的是ubuntu12.04.
sudo apt-get install flex g++ gawk zlib1g-dev libncurses5-dev libssl-dev subversion
先看一下它的目录树:
tree -d -L
.
├── config
├── docs
├── include
│ └── site
├── package
│ ├── base-files
│ ├── boot
│ ├── devel
│ ├── firmware
│ ├── kernel
│ ├── libs
│ ├── network
│ ├── system
│ └── utils
├── scripts
│ ├── config
│ └── flashing
├── target
│ ├── imagebuilder
│ ├── linux
│ ├── sdk
│ └── toolchain
├── toolchain
│ ├── binutils
│ ├── gcc
│ ├── gdb
│ ├── glibc
│ ├── insight
│ ├── kernel-headers
│ ├── musl
│ ├── uClibc
│ └── wrapper
└── tools
├── autoconf
├── automake
├── b43-tools
├── bc
├── bison
├── ccache
├── cloog
├── cmake
├── dosfstools
├── e2fsprogs
├── elftosb
├── findutils
├── firmware-utils
├── flex
├── flock
├── genext2fs
├── gengetopt
├── gmp
├── include
├── libelf
├── libtool
├── lzma
├── lzma-old
├── m4
├── missing-macros
├── mkimage
├── mklibs
├── mm-macros
├── mpc
├── mpfr
├── mtd-utils
├── mtools
├── padjffs2
├── patch
├── patchelf
├── patch-image
├── pkg-config
├── ppl
├── qemu
├── quilt
├── scons
├── sed
├── sparse
├── squashfs
├── squashfs4
├── sstrip
├── upslug2
├── upx
├── wrt350nv2-builder
├── xz
└── yaffs2
首先是更新一下feed:
./scripts/feeds update -a
./scripts/feeds install -a
这里的-a表示更新所有的feed,那么这里有哪些feed呢,可以从log里面看出来:
tan@love:~/openwrt-git/openwrt$ scripts/feeds update -a
Updating feed 'packages' from 'https://github.com/openwrt/packages.git' ...
Cloning into './feeds/packages'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
Receiving objects: % (/), 2.00 MiB | KiB/s, done.
Resolving deltas: % (/), done.
Create index file './feeds/packages.index'
Collecting package info: done
Collecting target info: done
Updating feed 'luci' from 'https://github.com/openwrt/luci.git' ...
Cloning into './feeds/luci'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
Receiving objects: % (/), 8.42 MiB | KiB/s, done.
Resolving deltas: % (/), done.
Create index file './feeds/luci.index'
Collecting package info: done
Collecting target info: done
Updating feed 'routing' from 'https://github.com/openwrt-routing/packages.git' ...
Cloning into './feeds/routing'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
Receiving objects: % (/), 242.46 KiB | KiB/s, done.
remote: Total (delta ), reused (delta ), pack-reused
Resolving deltas: % (/), done.
Create index file './feeds/routing.index'
Collecting package info: done
Collecting target info: done
Updating feed 'telephony' from 'https://github.com/openwrt/telephony.git' ...
Cloning into './feeds/telephony'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
Receiving objects: % (/), 140.49 KiB | KiB/s, done.
Resolving deltas: % (/), done.
Create index file './feeds/telephony.index'
Collecting package info: done
Collecting target info: done
Updating feed 'management' from 'https://github.com/openwrt-management/packages.git' ...
Cloning into './feeds/management'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
Unpacking objects: % (/), done.
Create index file './feeds/management.index'
Collecting package info: done
Collecting target info: done
Updating feed 'targets' from 'https://github.com/openwrt/targets.git' ...
Cloning into './feeds/targets'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
Receiving objects: % (/), 130.80 KiB | KiB/s, done.
Resolving deltas: % (/), done.
Create index file './feeds/targets.index'
Collecting package info: done
Collecting target info: done
可以从上面的网址看出来更新的feed。
更新feed后目录树的变化:
.
├── config
├── docs
├── feeds
│ ├── luci
│ ├── luci.tmp
│ ├── management
│ ├── management.tmp
│ ├── packages
│ ├── packages.tmp
│ ├── routing
│ ├── routing.tmp
│ ├── targets
│ ├── targets.tmp
│ ├── telephony
│ └── telephony.tmp
├── include
│ └── site
├── package
│ ├── base-files
│ ├── boot
│ ├── devel
│ ├── feeds
│ ├── firmware
│ ├── kernel
│ ├── libs
│ ├── network
│ ├── system
│ └── utils
├── scripts
│ ├── config
│ └── flashing
├── staging_dir
│ └── host
├── target
│ ├── imagebuilder
│ ├── linux
│ ├── sdk
│ └── toolchain
├── tmp
│ └── info
├── toolchain
│ ├── binutils
│ ├── gcc
│ ├── gdb
│ ├── glibc
│ ├── insight
│ ├── kernel-headers
│ ├── musl
│ ├── uClibc
│ └── wrapper
└── tools
├── autoconf
├── automake
├── b43-tools
├── bc
├── bison
├── ccache
├── cloog
├── cmake
├── dosfstools
├── e2fsprogs
├── elftosb
├── findutils
├── firmware-utils
├── flex
├── flock
├── genext2fs
├── gengetopt
├── gmp
├── include
├── libelf
├── libtool
├── lzma
├── lzma-old
├── m4
├── missing-macros
├── mkimage
├── mklibs
├── mm-macros
├── mpc
├── mpfr
├── mtd-utils
├── mtools
├── padjffs2
├── patch
├── patchelf
├── patch-image
├── pkg-config
├── ppl
├── qemu
├── quilt
├── scons
├── sed
├── sparse
├── squashfs
├── squashfs4
├── sstrip
├── upslug2
├── upx
├── wrt350nv2-builder
├── xz
└── yaffs2
然后使用:
make menuconfig
make
编译的过程会持续好几个小时,因为编译的时候还需要在线下载工具包,如果网络慢的话就会
更慢了。
关于make的作用,README是这样说的:
Simply running "make" will build your firmware.
It will download all sources, build the cross-compile toolchain,
the kernel and all choosen applications.
中文手册是这样说的:
OpenWrt选择了另一种方式来生成固件:下载,打补丁,编译,一切从零开始,即使交叉编译链也是如此。
一开始下载openwrt源码的时候,也就大约300MB,但是里面基本上没有代码,大部分
都是配置文件。
openwrt的英文文档如下:
https://downloads.openwrt.org/kamikaze/docs/openwrt.html
在编译过程中,使用make -j V=99 可以加快编译速度,并且显示所有信息,
在编译的时候,我的swap被占满,并且报错,可能是因为屏幕上刷的太快导致的:
virtual memory exhaustedvirtual memory exhausted
不打开V=99的情况下,我的编译log如下:
tan@ubuntu:~/openwrt$ make -j4
make[] world
make[] target/compile
make[] package/cleanup
make[] -C target/linux compile
make[] package/compile
make[] -C package/system/opkg host-compile
make[] -C package/libs/toolchain compile
make[] -C package/kernel/gpio-button-hotplug compile
make[] -C package/libs/ncurses host-compile
make[] -C package/libs/libnl-tiny compile
make[] -C package/utils/lua compile
make[] -C package/libs/libjson-c compile
make[] -C package/libs/lzo compile
make[] -C package/libs/zlib compile
make[] -C package/libs/ncurses compile
make[] -C package/boot/uboot-ar71xx compile
make[] -C package/firmware/linux-firmware compile
make[] -C package/libs/ocf-crypto-headers compile
make[] -C package/network/utils/iw compile
make[] -C package/network/services/dropbear compile
make[] -C package/libs/libpcap compile
make[] -C package/network/utils/linux-atm compile
make[] -C package/network/utils/resolveip compile
make[] -C package/utils/busybox compile
make[] -C package/libs/libubox compile
make[] -C package/utils/util-linux compile
make[] -C package/kernel/linux compile
make[] -C package/libs/openssl compile
make[] -C package/system/ubus compile
make[] -C package/system/uci compile
make[] -C package/utils/jsonfilter compile
make[] -C package/system/mtd compile
make[] -C package/system/opkg compile
make[] -C package/network/config/netifd compile
make[] -C package/system/ubox compile
make[] -C package/utils/ubi-utils compile
make[] -C package/network/services/hostapd compile
make[] -C package/network/config/swconfig compile
make[] -C package/network/services/odhcpd compile
make[] -C package/network/utils/iwinfo compile
make[] -C package/system/procd compile
make[] -C package/system/fstools compile
make[] -C package/base-files compile
make[] -C package/boot/uboot-envtools compile
make[] -C package/kernel/mac80211 compile
make[] -C package/network/utils/iptables compile
make[] -C package/network/services/dnsmasq compile
make[] -C package/network/ipv6/odhcp6c compile
make[] -C package/network/services/ppp compile
make[] -C package/network/config/firewall compile
make[] package/install
make[] package/preconfig
make[] target/install
make[] -C target/linux install
make[] package/index
最终会生成下面的文件(在bin文件夹内):

由于我使用默认的配置,生成的文件太多,这里只给一个部分的截图
初次下载源代码,为了理解openwrt的架构和编译过程,下面做一下简要的分析:
openwrt是基于linux kernel的,并且使用uclibc作为c库。
注意到编译过程中生成了三个文件夹,那么他们分别是干什么的呢?
dl build_dir staging_dir
dl是在编译的时候下载文件的目录,这些文件都是编译所需要的,下面是它们的的一部分:
├── ath10k-firmware-da0f85d924226ee30c46e037120621c9e192b39e.tar.bz2
├── autoconf-2.69.tar.xz
├── automake-1.15.tar.xz
├── bc-1.06..tar.bz2
├── binutils-linaro-2.24.-2014.09.tar.xz
├── bison-3.0..tar.xz
├── broadcom-wl-4.150.10.5.tar.bz2
├── broadcom-wl-5.100..tar.bz2
├── busybox-1.23..tar.bz2
├── cmake-2.8.12.2.tar.gz
├── compat-wireless---.tar.bz2
├── dnsmasq-2.72.tar.gz
├── dropbear-2014.65.tar.bz2
├── e2fsprogs-1.42..tar.gz
├── findutils-4.4..tar.gz
├── firewall----165029cb8c0f1545628f44143aec965e64cef021.tar.gz
├── flex-2.5..tar.bz2
├── fstools----a5fa5b6144253726dcd7e769197eed787a723f5f.tar.gz
├── gcc-linaro-4.8-2014.04.tar.xz
├── gdb-linaro-7.6-2013.05.tar.bz2
├── genext2fs-1.4..tar.gz
├── gengetopt-2.22..tar.gz
├── gmp-5.1..tar.xz
├── hostapd---.tar.bz2
├── iptables-1.4..tar.bz2
├── ipw2100-fw-1.3.tgz
├── ipw2200-fw-3.1.tgz
├── iw-3.17.tar.xz
├── json-c-0.12.tar.gz
├── jsonfilter----cdc760c58077f44fc40adbbe41e1556a67c1b9a9.tar.gz
├── libelf-0.8..tar.gz
├── libiwinfo----40f2844fadc05f4a4de7699dbc12fee295b7057b.tar.gz
├── libpcap-1.5..tar.gz
├── libtool-2.4.tar.gz
├── libubox----b8d9b382e39823850331edc2a92379173daf1be3.tar.gz
├── linux-3.18..tar.xz
├── linux-atm-2.5..tar.gz
├── linux-firmware----f404336ba808cbd57547196e13367079a23b822c.tar.bz2
├── lua-5.1..tar.gz
注意到,这些都是从网上下载的,要注意保留,以后编译的时候就不用上网下载了。
而build_dir的作用就是存放上述这些压缩包的解压路径,也就是说,dl的包会解压到build_dir里面,
并且编译这些包。
其中,这里有三个目录:
tan@ubuntu:~/openwrt$ tree build_dir/ -d -L
build_dir/
├── host
├── target-mips_34kc_uClibc-0.9.33.2
└── toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2
host目录是为了编译一些tools用于协助生成openwrt image
target目录是为目标主机编译用的,可以在目录上看到CPU的架构和所用的c库
toolchain是用来编译交叉编译器的
在staging_dir下面可以看到类似的三个目录:
tan@ubuntu:~/openwrt$ tree staging_dir/ -d -L
staging_dir/
├── host
├── target-mips_34kc_uClibc-0.9.33.2
└── toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2
host目录下存放了一些编译主机上的一些工具(tools)
target 目录主要存放编译出来的firmware,是给目标机器用的
toolchain目录包含了交叉编译器,你可以在里面写一个简单的c文件,并且使用交叉编译器编译它,
生成的程序可以在目标机器上运行。
虽然不完全如此,可以将staging_dir的每个文件夹对应理解成build_dir的产物
这里有编译过程的大体介绍:
http://wiki.openwrt.org/doc/howto/build
http://downloads.openwrt.org/docs/buildroot-documentation.html
openwrt是一个高度定制版的buildroot,官网有它的介绍:
http://wiki.openwrt.org/about/toolchain
使用这个系统,可以基本做到全自动的编译过程。
bin目录下面的文件粗看可以分为两类:
openwrt-ar71xx-generic-a02-rb-w300n-squashfs-factory.bin
openwrt-ar71xx-generic-a02-rb-w300n-squashfs-sysupgrade.bin
其中这两个的区别是(转自http://see.sl088.com/wiki/Openwrt_factory%E5%9B%BA%E4%BB%B6/%E4%B8%BA%E4%BD%95%E5%85%88%E5%88%B7factory):
factory是用来从原厂固件升级到openwrt用的。 sysupgrade是用来给openwrt升级用的
无论你是升级还是从官方方刷openwrt,openwrt-XXXXXXX-factory.bin的固件都是适用的。 而openwrt-XXXXXXX-sysupgrade.bin.固件只能用来升级用。如TTL救砖就不能用sysupgrade的固件。
其中这里又进一步说明了:
http://www.cnblogs.com/siikee/p/4224086.html
bin文件下还有很多ipk文件,这些文件是opkg包管理系统的文件,在openwrt
运行起来的时候可以使用opkg安装,用起来和debian的deb差不多。
另外,openwrt 官方说了,the bootloader is not part of OpenWrt
http://wiki.openwrt.org/doc/techref/bootloader
而且,bootloader对于每一个路由器都是不一样的,负责将最底层开起来。厂家也不见得会将最底层的
代码开源。
目前有很多卖修改好的openwrt路由器,一个卖点就是不死uboot,就是说
你的firmware不管怎么刷都可以恢复,它包括一个网页接口,可以上传firmware
到路由器上,这样大大方便了openwrt的调试。
openwrt的menuconfig是定制好的,项目在config**.in里面:

最后看看openwrt 的patch系统

package的很多子目录都包含这两个东西,patches 是一些patch,Makefile包含了下载地址和其他的一些信息。
当发现这些用户空间软件出问题的时候,为其加patch就可以了,
实际上linux kernel出问题时,也可以这样类似地对其加一些patch进去。
Openwrt 初探的更多相关文章
- Openwrt Image Builder/SDK 初探
image builder和SDK既可以从官网上下载,又可以自己进行编译(make menuconfig).官网上下载的是预先帮你编译好的,这样可以大量节省自己编译源码花的时间,这两个东西相当于半成品 ...
- 【玩转开源】BananaPi R2 —— 第四篇 Openwrt Luci 初探
什么是Luci呢?先直观的感受一下,打开web浏览器,输入R2的网关地址,然后出现了一个web登录界面,这个就是Openwrt Luci的应用. 那么到底什么是Luci呢?在这里我先给大家一个公式:L ...
- OpenWrt中开启usb存储和samba服务
在从官网安装的WNDR3800 15.05.1版本OpenWrt中, 不带usb存储支持以及samba, 需要另外安装 1. 启用usb支持 USB Basic Support https://wik ...
- 初探领域驱动设计(2)Repository在DDD中的应用
概述 上一篇我们算是粗略的介绍了一下DDD,我们提到了实体.值类型和领域服务,也稍微讲到了DDD中的分层结构.但这只能算是一个很简单的介绍,并且我们在上篇的末尾还留下了一些问题,其中大家讨论比较多的, ...
- (转)利用libcurl和国内著名的两个物联网云端通讯的例程, ubuntu和openwrt下调试成功(四)
1. libcurl 的参考文档如下 CURLOPT_HEADERFUNCTION Pass a pointer to a function that matches the following pr ...
- (转)利用libcurl获取新浪股票接口, ubuntu和openwrt实验成功(三)
1. 利用 CURLOPT_WRITEFUNCTION 设置回调函数, 利用 CURLOPT_WRITEDATA 获取数据指针 官网文档如下 CALLBACK OPTIONS CURLOPT_WRI ...
- (转)linux下和云端通讯的例程, ubuntu和openwrt下实验成功(二)
前言: 上节用纯linux的函数实现了和云端通讯, 本节开始利用传说中的神器libcurl 话说一个网络程序员对书法十分感兴趣,退休后决定在这方面有所建树. 于是花重金购买了上等的文房四宝. 一 ...
- (转)linux下和云端通讯的例程, ubuntu和openwrt实验成功(一)
一. HTTP请求的数据流总结#上传数据, yeelink的数据流如下POST /v1.0/device/4420/sensor/9089/datapoints HTTP/1.1Host: api. ...
- CSharpGL(8)使用3D纹理渲染体数据 (Volume Rendering) 初探
CSharpGL(8)使用3D纹理渲染体数据 (Volume Rendering) 初探 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码 ...
随机推荐
- ubuntu下安装wireshark
ubuntu下安装wireshark download: http://www.wireshark.org/download.html choose source code 安装编译工具: $s ...
- 关于统计变换(CT/MCT/RMCT)算法的学习和实现
原文地址http://blog.sina.com.cn/s/blog_684c8d630100turx.html 刚开会每周的例会,最讨厌开会了,不过为了能顺利毕业,只能忍了.闲话不多说了,下面把上周 ...
- hdu 3367 Pseudoforest(最大生成树)
Pseudoforest Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- git 换行符LF与CRLF转换问题
git 换行符LF与CRLF转换问题 一.背景 在各操作系统下,文本文件所使用的换行符是不一样的.UNIX/Linux 使用的是 0x0A(LF),早期的 Mac OS 使用的是0x0D(CR),后来 ...
- CocurrentHashMap和Hashtable的区别
集合类是Java API的核心,但是我觉得要用好它们是一种艺术.我总结了一些个人的经验,譬如使用ArrayList能够提高性能,而不再需要过时的Vector了,等等.JDK 1.5引入了一些好用的并发 ...
- 半径无关单核单线程最快速高斯模糊实现(附完整C代码)
之前,俺也发过不少快速高斯模糊算法. 俺一般认为,只要处理一千六百万像素彩色图片,在2.2GHz的CPU上单核单线程超过1秒的算法,都是不快的. 之前发的几个算法,在俺2.2GHz的CPU上耗时都会超 ...
- js对Date对象的操作的问题(生成一个倒数7天的数组)
今天在论坛上看到这样一个问题如下: 问题描述: 使用JavaScript生成一个倒数7天的数组.比如今天是10月1号,生成的数组是["9月25号","9月26号" ...
- 如何显示隐藏的Administrator账户
在Windows XP中,Administrator帐户是终极管理员,如果你创建了其他管理员帐户,那么该帐户就会从欢迎屏幕上被隐藏.这里需要注意的是,仅仅是从欢迎屏幕上被隐藏,该帐户仍然存在. 如 ...
- React 之 Hello world
一入react深似海,从此学习为常态,react 成为了一种趋势,很多人应该很多人准备进坑,下面对react进行简单的描述: 首先学习react,要有多方学习的准备,例如:Webpack, Babel ...
- Unity4.6新UI系统初探(uGUI)
一.引言 Unity终于在即将到来的4.6版本内集成了所见即所得的UI解决方案(视频).事实上从近几个版本开始,Unity就在为这套系统做技术扩展,以保证最终能实现较理想的UI系统.本文试图通过初步的 ...