最近想研究一下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 初探的更多相关文章

  1. Openwrt Image Builder/SDK 初探

    image builder和SDK既可以从官网上下载,又可以自己进行编译(make menuconfig).官网上下载的是预先帮你编译好的,这样可以大量节省自己编译源码花的时间,这两个东西相当于半成品 ...

  2. 【玩转开源】BananaPi R2 —— 第四篇 Openwrt Luci 初探

    什么是Luci呢?先直观的感受一下,打开web浏览器,输入R2的网关地址,然后出现了一个web登录界面,这个就是Openwrt Luci的应用. 那么到底什么是Luci呢?在这里我先给大家一个公式:L ...

  3. OpenWrt中开启usb存储和samba服务

    在从官网安装的WNDR3800 15.05.1版本OpenWrt中, 不带usb存储支持以及samba, 需要另外安装 1. 启用usb支持 USB Basic Support https://wik ...

  4. 初探领域驱动设计(2)Repository在DDD中的应用

    概述 上一篇我们算是粗略的介绍了一下DDD,我们提到了实体.值类型和领域服务,也稍微讲到了DDD中的分层结构.但这只能算是一个很简单的介绍,并且我们在上篇的末尾还留下了一些问题,其中大家讨论比较多的, ...

  5. (转)利用libcurl和国内著名的两个物联网云端通讯的例程, ubuntu和openwrt下调试成功(四)

    1. libcurl 的参考文档如下 CURLOPT_HEADERFUNCTION Pass a pointer to a function that matches the following pr ...

  6. (转)利用libcurl获取新浪股票接口, ubuntu和openwrt实验成功(三)

    1.  利用 CURLOPT_WRITEFUNCTION 设置回调函数, 利用 CURLOPT_WRITEDATA 获取数据指针 官网文档如下 CALLBACK OPTIONS CURLOPT_WRI ...

  7. (转)linux下和云端通讯的例程, ubuntu和openwrt下实验成功(二)

    前言: 上节用纯linux的函数实现了和云端通讯, 本节开始利用传说中的神器libcurl 话说一个网络程序员对书法十分感兴趣,退休后决定在这方面有所建树. 于是花重金购买了上等的文房四宝.    一 ...

  8. (转)linux下和云端通讯的例程, ubuntu和openwrt实验成功(一)

    一.  HTTP请求的数据流总结#上传数据, yeelink的数据流如下POST /v1.0/device/4420/sensor/9089/datapoints HTTP/1.1Host: api. ...

  9. CSharpGL(8)使用3D纹理渲染体数据 (Volume Rendering) 初探

    CSharpGL(8)使用3D纹理渲染体数据 (Volume Rendering) 初探 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码 ...

随机推荐

  1. XtraScheduler 日程控件显示自定义标题

    下面代码实现一个自定义日程标题 public class CustomHeaderCaptionService : HeaderCaptionServiceWrapper { public Custo ...

  2. 【转】PaxosLease算法--2PC看Paxos选主

    原文请参考[[置顶] Paxos master选举--PaxosLease算法] 众所周知,为了避免Paxos算法的活锁问题,必须选举唯一的proposor.偏偏在Paxos原论文中,作者L. Lam ...

  3. MySql查询语句中解决“该列没有包含在聚合函数或者groupby子句中”的相关问题方法

    首先引入语句来源,表结构和数据如下: 需求是:查出员工(personname)在不同店铺(store)的总薪酬(salary),相同店铺输出store,不同店铺输出multi_store. 正确查询语 ...

  4. Navicat for Mysql远程连接数据时报(1045错误)Access denied for user 'root'@'localhost' (using password yes);

    原因:用户访问被拒绝,更改用户赋予密码即可 mysql命令行执行语句如下 //使用mysql,读取表信息 //更改用户赋予登录密码 //更新权限 注意点:使用flush privileges是为了刷新 ...

  5. 烂泥:centos安装及配置DNS服务器

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 要在centos配置DNS服务器,要先安装DNS软件BIND.当然我们也可以安装其他的DNS软件,比如国内的开源DNS软件DNSPod. 在此我们以通过 ...

  6. 烂泥:ubuntu安装KVM虚拟机管理virt-manager

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 打算学习KVM的图形界面管理器virt-manager,但是virt-manager只有linux系统的,没有windows下的.所以只能使用linux ...

  7. python基础入门

    Python简介 python是吉多·范罗苏姆发明的一种面向对象的脚本语言,可能有些人不知道面向对象和脚本具体是什么意思,但是对于一个初学者来说,现在并不需要明白.大家都知道,当下全栈工程师的概念很火 ...

  8. Maven使用笔记,错误Failure to Transfer后处理

    当有未更新成功的项,M3会以后缀为.lastUpdated保存未更新成功的项 执行下面的操作可清楚这些项 Unixfind ~/.m2 -name "*.lastUpdated" ...

  9. STL的erase()陷阱-迭代器失效总结

    下面材料整理自Internet&著作. STL中的容器按存储方式分为两类,一类是按以数组形式存储的容器(如:vector .deque):另一类是以不连续的节点形式存储的容器(如:list.s ...

  10. redis unwatch discard

    UNWATCH UNWATCH 取消 WATCH 命令对所有 key 的监视. 如果在执行 WATCH 命令之后, EXEC 命令或 DISCARD 命令先被执行了的话,那么就不需要再执行UNWATC ...