标签 openwrt wifidog 下的文章

OpenWrt Buildroot 基础教程

Prerequisites

to generate an installable OpenWrt firmware image file with a size of e.g. 8MB:

Install OpenWrt Buildroot and its prerequisites on your OS.
ca. 3-4 GB of available hard disk space
environment variables:
SED should not be set. If it is, run unset SED before compiling. (See Ticket 10612.)
GREP_OPTIONS should not have –initial-tab or other options affecting its output
Add /staging_dir/host/bin and /staging_dir/toolchain---/bin in front of your PATH variable in ~/.bashrc. The staging directory is created shortly after starting the build and the toolchain directory is created when the toolchain build begins. The build spawns multiple shells, some of which expect the toolchain binaries to be present in the PATH.
Procedure

  1. Update OpenWrt sources.
  2. Update and install package feeds.
  3. Configure the firmware image you want to obtain.
  4. Start the build. This will automatically compile toolchain,cross-compile sources, package packages, and finally generate an image ready to be flashed.
  5. Proceed to Installing OpenWrt

Updating Sources with Git

git pull

Updating Feeds
Update feeds:

./scripts/feeds update -a

Make downloaded package/packages available in make menuconfig:
single package:

./scripts/feeds install <PACKAGENAME>

all packages:

./scripts/feeds install -a

Image Configuration
Typical actions:

  1. run make menuconfig and set target;
  2. run make defconfig;
  3. run make menuconfig and modify set of package;
  4. run scripts/diffconfig.sh >mydiffconfig (save your changes in the
    text file mydiffconfig);
  5. run make V=s (build OpenWRT with console logging, you will look
    where build failed.).

Make menuconfig
The OpenWrt Buildroot configuration interface handles the selection of the target platform, packages to be compiled, packages to be included in the firmware file, some kernel options, etc.
Start the OpenWrt Buildroot configuration interface by issuing the following command:

make menuconfig

This will update the dependencies of your existing configuration automatically, and you can now proceed to build your updated images.

You have three options: y, m, n which are represented as follows:

pressing y sets the <*> built-in label
This package will be compiled and included in the firmware image file.
pressing m sets the package label
This package will be compiled, but not included in the firmware image file. (E.g. to be installed with opkg after flashing the firmware image file to the device.)
pressing n sets the < > excluded label
The source code will not be processed.
When you save your configuration, the file /.config will be created according to your configuration.

make kernel_menuconfig CONFIG_TARGET=subtarget
make defconfig
make or make world

The make sequience

Top command make world calls the following sequence of the commands:

make target/compile
make package/cleanup
make package/compile
make package/install
make package/preconfig
make target/install
make package/index

You may run each command independency. For example, if the process of compilation of packages stops on error, you may fix problem and next continue without cleanup:

make package/compile
make package/install
make package/preconfig
make target/install
make package/index

Warnings, errors and tracing

make V=s or make V=99

本文章由http://www.wifidog.pro/2015/08/02/OpenWrt-%E7%BC%96%E8%AF%91.html整理编辑,转载请注明出处

openwrt uci系统语法

在UCI的配置文件通常包含一个或多个配置语句,包含一个或多个用来定义实际值的选项语句的所谓的节。

下面是一个简单的配置示例文件:

package 'example'

config 'example' 'test'
        option   'string'      'some value'
        option   'boolean'     '1'
        list     'collection'  'first item'
        list     'collection'  'second item'

config 'example' 'test' 语句标志着一个节的开始。这里的配置类型是example,配置名是test。配置中也允许出现匿名节,即自定义了配置类型,而没有配置名的节。配置类型对应配置处理程序来说是十分重要的,因为配置程序需要根据这些信息来处理这些配置项。
option 'string' 'some value' 和 option 'boolean' '1' 定义了一些简单值。文本选项和布尔选项在语法上并没有差异。布尔选项中可以用'0' , 'no', 'off', 或者'false'来表示false值,或者也可以用'1', 'yes','on'或者'true'来表示真值。
以list关键字开头的多个行,可用于定义包含多个值的选项。所有共享一个名称的list语句,会组装形成一个值列表,列表中每个值出现的顺序,和它在配置文件中的顺序相同。如上例种中,列表的名称是'collection',它包含了两个值,即'first item'和'second item'。
'option'和'list'语句的缩进可以增加配置文件的可读性,但是在语法不是必须的。
通常不需要为标识符和值加引号,只有当值包括空格或者制表符的时候,才必须加引号。同时,在使用引号的时候,可以用双引号代替单引号。

下面列举的例子都是符合uci语法的正确配置:

option example value
option 'example' value
option example "value"
option "example"    'value' 
option   'example' "value"

反之,以下配置则存在语法错误

option 'example" "value' (引号不匹配)
option example some value with space (值中包含空格,需要为值加引号)
还有一点是必须知道的,即UCI标识符和配置文件名称所包含的字符必须是由a-z, 0-9和_组成。 选项值则可以包含任意字符,只要这个值是加了引号的。

命令行实用工具

使用awk、grep等命令来解析Openwr的配置文件是低效和不明智的做法,建议用户通过uci工具对openwrt进行配置。

下面将给出一些例子,来展示uci这个强大的工具。

用法
root@OpenWrt:/lib/config# uci

用法: uci [] []

命令:

batch
export     [<config>]
import     [<config>]
changes    [<config>]
commit     [<config>]
add        <config> <section-type>
add_list   <config>.<section>.<option>=<string>
show       [<config>[.<section>[.<option>]]]
get        <config>.<section>[.<option>]
set        <config>.<section>[.<option>]=<value>
delete     <config>[.<section[.<option>]]
rename     <config>.<section>[.<option>]=<name>
revert     <config>[.<section>[.<option>]]

参数:

-c <path>  set the search path for config files (default: /etc/config)
-d <str>   set the delimiter for list values in uci show
-f <file>  use <file> as input instead of stdin
-m         when importing, merge data into an existing package
-n         name unnamed sections on export (default)
-N         don't name unnamed sections
-p <path>  add a search path for config change files
-P <path>  add a search path for config change files and use as default
-q         quiet mode (don't print error messages)
-s         force strict mode (stop on parser errors, default)
-S         disable strict mode
-X         do not use extended syntax on 'show'

例子:

导出整个配置

root@OpenWrt:~# uci export uhttpd
package 'uhttpd'

config 'uhttpd' 'main'
    list 'listen_http' '0.0.0.0:80'
    list 'listen_http' '0.0.0.0:8080'
    list 'listen_https' '0.0.0.0:443'
    option 'home' '/www'
    option 'rfc1918_filter' '1'
    option 'cert' '/etc/uhttpd.crt'
    option 'key' '/etc/uhttpd.key'
    option 'cgi_prefix' '/cgi-bin'
    option 'script_timeout' '60'
    option 'network_timeout' '30'
    option 'tcp_keepalive' '1'

config 'cert' 'px5g'
    option 'days' '730'
    option 'bits' '1024'
    option 'country' 'DE'
    option 'state' 'Berlin'
    option 'location' 'Berlin'
    option 'commonname' 'OpenWrt'

root@OpenWrt:~#

查看所有配置项的值

root@OpenWrt:~# uci show uhttpd
uhttpd.main=uhttpd
uhttpd.main.listen_http=0.0.0.0:80 0.0.0.0:8080
uhttpd.main.listen_https=0.0.0.0:443
uhttpd.main.home=/www
uhttpd.main.rfc1918_filter=1
uhttpd.main.cert=/etc/uhttpd.crt
uhttpd.main.key=/etc/uhttpd.key
uhttpd.main.cgi_prefix=/cgi-bin
uhttpd.main.script_timeout=60
uhttpd.main.network_timeout=30
uhttpd.main.tcp_keepalive=1
uhttpd.px5g=cert
uhttpd.px5g.days=730
uhttpd.px5g.bits=1024
uhttpd.px5g.country=DE
uhttpd.px5g.state=Berlin
uhttpd.px5g.location=Berlin
uhttpd.px5g.commonname=OpenWrt
root@OpenWrt:~#

查看特定配置项的值

root@OpenWrt:~# uci get uhttpd.@uhttpd[0].listen_http
0.0.0.0:80 0.0.0.0:8080
root@OpenWrt:~#

查询网络接口的状态

root@OpenWrt:~# uci -P/var/state show network.wan
network.wan=interface
network.wan.ifname=eth0.1
network.wan.proto=dhcp
network.wan.defaultroute=0
network.wan.peerdns=0
network.wan.device=eth0.1
network.wan.ipaddr=10.11.12.13
network.wan.broadcast=255.255.255.255
network.wan.netmask=255.255.255.0
network.wan.gateway=10.11.12.1
network.wan.dnsdomain=
network.wan.dns=10.11.12.100 10.11.12.200
network.wan.up=1
network.wan.lease_gateway=10.11.12.1
network.wan.lease_server=10.11.12.25
network.wan.lease_acquired=1262482940
network.wan.lease_lifetime=5400
network.wan.lease_hostname=x-10-11-12-13
root@OpenWrt:~#

添加防火墙规则

这是一个添加SSH端口转发到防火墙规则的例子,和'-1'使用的一个例子。

root@OpenWrt:~# uci add firewall rule
root@OpenWrt:~# uci set firewall.@rule[-1].src=wan
root@OpenWrt:~# uci set firewall.@rule[-1].target=ACCEPT
root@OpenWrt:~# uci set firewall.@rule[-1].proto=tcp
root@OpenWrt:~# uci set firewall.@rule[-1].dest_port=22
root@OpenWrt:~# uci commit firewall
root@OpenWrt:~# /etc/init.d/firewall restart

本文章由http://www.wifidog.pro/2015/07/27/openwrt-uci%E8%AF%AD%E6%B3%95.html整理编辑,转载请注明出处

openwrt 固件的uci系统

UCI系统
"uci"是"Unified Configuration Interface"(统一配置界面)的缩写,意在OpenWrt整个系统的配置集中化。

系统配置应容易,更直接且在此有文档描述,从而使你的生活更轻松!

(它是White Russian系列OpenWrt基于nvram的配置的后继改进。)

许多程序在系统某处拥有自己的配置文件,

比如/etc/network/interfaces, /etc/exports, /etc/dnsmasq.conf或者 /etc/samba/samba.conf,

有时它们还使用稍有不同的语法。

在OpenWrt中你无需为此烦恼,我们只需更改UCI配置文件!

你不需要为了某个更改起效而重启系统!参阅下文中的命令行实用工具以了解如何做到这点。

还有不要忘了官方程序包(official binaries)里包含了很多后台程序,但默认情况下并未启用!

比如cron后台程序默认并未激活,因而只编辑crontab并无作用。

你需要用/etc/init.d/crond start起动它或用/etc/init.d/crond enable激活它。 大部分后台程序都可以disable(禁用),stop(停止)和restart(重起)。 还有一些非UCI配置你可以参阅。

共同原则

OpenWrt的所有配置文件皆位于/etc/config/目录下。每个文件大致与它所配置的那部分系统相关。可用文本编辑器、"uci" 命令行实用程序或各种编程API(比如 Shell, Lua and C)来编辑/修改这些配置文件。

配置文件

文件位置 描述
基本配置
/etc/config/dhcp dnsmasq和DHCP的配置
/etc/config/dropbear SSH服务端选项
/etc/config/firewall 中央防火墙配置
/etc/config/network 交换,接口和路由配置
/etc/config/system 杂项与系统配置
/etc/config/timeserver rdate的时间服务器列表
/etc/config/wireless 无线设置和无线网络的定义
IPv6
/etc/config/ahcpd Ad-Hoc配置协议(AHCP) 服务端配置以及转发器配置
/etc/config/aiccu AICCU 客户端配置
/etc/config/dhcp6c WIDE-DHCPv6 客户端配置
/etc/config/dhcp6s WIDE-DHCPv6 服务端配置
/etc/config/gw6c GW6c 客户端配置
/etc/config/radvd 路由通告 (radvd) 配置
其他
/etc/config/etherwake 以太网唤醒: etherwake
/etc/config/fstab 挂载点及swap
/etc/config/hd-idle 另一个可选的硬盘空闲休眠进程(需要路由器支持usb硬盘)
/etc/config/httpd 网页服务器配置选项(Busybox 自带httpd, 已被舍弃)
/etc/config/luci 基础 LuCI 配置
/etc/config/luci_statistics 包统计配置
/etc/config/mini_snmpd mini_snmpd 配置
/etc/config/mountd OpenWrt 自动挂载进程(类似autofs)
/etc/config/multiwan 简单多WAN出口配置
/etc/config/ntpclient ntp客户端配置,用以获取正确时间
/etc/config/pure-ftpd Pure-FTPd 服务端配置
/etc/config/qos QoS配置(流量限制与整形)
/etc/config/samba samba配置(Microsoft文件共享)
/etc/config/snmpd SNMPd(snmp服务进程) 配置
/etc/config/sshtunnel sshtunnel配置
/etc/config/stund STUN 服务端配置
/etc/config/transmission BitTorrent配置
/etc/config/uhttpd Web服务器配置(uHTTPd)
/etc/config/upnpd miniupnpd UPnP服务器配置
/etc/config/ushare uShare UPnP 服务器配置
/etc/config/vblade vblade 用户空间AOE(ATA over Ethernet)配置
/etc/config/vnstat vnstat 下载器配置
/etc/config/wifitoogle 使用按钮来开关WiFi的脚本
/etc/config/wol Wake-on-Lan: wol
/etc/config/znc ZNC 配置

本文章由http://www.wifidog.pro/2015/07/23/openwrt-uci.html整理编辑,转载请注明出处

openwrt刷固件恢复原厂固件

There is little point in merely uninstalling OpenWrt, what you actually want to do, is to replace OpenWrt with the original firmware. You are here, because the wiki-page for your device, does not help you with that. So, first have a look at the flash.layout

To replace OpenWrt with the original firmware, you most probably do not have to change the boot partition, or the partition containing specific information like NVRAM or ART. Even if you overwrote the bootloader when you installed OpenWrt on your device.

通过OpenWrt CLI恢复原厂

You can use the program mtd for this:

cd /tmp
wget http://www.example.org/original_firmware.bin
mtd -r write /tmp/original_firmware.bin firmware

OpenWrt has no built-in "pleasantries" to prevent you from going back to original firmware. But sometimes you need to be careful, see e.g. back.to.original.firmware.

If you get a error message on the above mtd command like "no valid command given" you are using an old version of mtd which doesn't support the -r or -e parameters.

Download a newer statically compiled version

cd /tmp
wget http://www.freewrt.org/downloads/tools/mtd-static
chmod a+x mtd.static
wget http://www.example.org/original.trx
./mtd.static -e linux -r write original.trx linux

TIP: PLEASE READ - Common mistakes thread section 2 also. It describes when you should use the

openwrt-brcm-2.4-squashfs.trx

image.
Only flash a trx, never flash a bin file?
If you only have a Linksys .bin firmware file, this is not a problem, simply cut off the header before using the commands below:

dd bs=32 skip=1 if=original.bin of=original.trx

TIP: If your replacement firmware has a web interface, remember to flush your browser cache, sessions etc. This will avoid misleading 404 errors.

通过OpenWrt的WebUI管理界面恢复原厂固件
通过 Booloader恢复原厂固件

To flash the original firmware back again via the bootloader, please follow the procedures already described in Installing OpenWrt. They are basically the same.

本文章由http://www.wifidog.pro/2015/07/16/openwrt%E5%8D%87%E7%BA%A7%E5%9B%BA%E4%BB%B6-1.html整理编辑,转载请注明出处