标签 openwrt开发 下的文章

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 web管理luci界面修改

1.jpg

以前都没听过openwrt和luci,只接触过简单的php语言。由于工作原因,要修改下luci的界面,竟然用了我2天的时间才简单的了解了luci的用法。这里简单的和大家分享下。(就接触2天,本人又是菜鸟级别,高手直接略过吧)大家发现有什么错误就和我说下大家共同学习。我主要是想修改下open后台界面网页的内容。

具体怎么安装已经有人介绍过来了,我就不详细说了。下面说配置好之后,修改UI的做法

在浏览器中输入:http://192.168.1.1/ 会自动跳到http://192.168.1.1/cgi-bin/luci 登陆默认root 密码是空

默认的几个一级菜单都是在modules\admin-full\luasrc\controller\admin\ 这个目录下

这个就类似于php的根目录了。/etc/config/这个目录下面的文件,个人观点是可以把它当做是php中的数据库连看待,这样反而更方便理解。

实际上luci界面提供的已经很全了,我们并没有多少必要要新建立页面,我们大多就是在已有的界面上添加一些内容。比如我们公司现在需要添加wifi的isolate和maxassoc这两项属性。就让我找了半天才找到
wifi.jpg

首先要找到network-wifi对应的文件,

在找点击edit后页面对应的文件。
wifi-edit.jpg

network.lua这个文件里面就定义了network下面有哪些二级目录。

比如我要改wifi,我就看到有

if has_wifi and has_wifi.size > 0 then page = entry({“admin”, “network”, “wireless”}, arcombine(template(“admin_network/wifi_overview”), cbi(“admin_network/wifi”)), _(“Wifi”), 15) page.leaf = true page.subindex = true

这里面有cbi(“admin_network/wifi”)这条语句。知道的人就知道,不知道也没关系,想知道可以自己查下。

这时我们到目录\modules\admin-full\luasrc\model\cbi\admin_network\下面可以发现一个wifi.lua的文件,cbi的语句就是指向的这个文件。我们打开wifi.lua后,在———————- Interface ———————–这个下面地方添加

isolate = s:taboption(“advanced”, Flag, “isolate”, translate(“Separate Clients”),translate(“Prevents client-to-client communication”))

maxassoc = s:taboption(“advanced”, Value, “maxassoc”, translate(“Connection Limi”),translate(“Specifies the maximum number of clients to connect.”))

这样两条语句就可以了。进入network-wifi edit看下我们修改的效果

我们进入network-wifi之后选择一个无线网络点击edit后进入页面
example.jpg

在Interface Configuration下面的Advanced Settings下面可以进行修改之后点击Save & Apply

修改这两项是保存在什么地方呢?刚刚我说了,/etc/config/目录下相当于数据库的功能。

这时我们vi /etc/config/wireless可以查看到我们刚刚修改内容。
wireless-config.jpg

可以看到已经修改为我们刚刚调整的77了。

有的人想要添加新的页面和功能,可以看下下面的内容。

下面内容来源于chaochaoblog

要完成一个新模块并用到里面需要两个东西,

第一个我们先找到usr/lib/lua/LuCI/controller在里面建立一个文件夹,也就是我们的模块名称,就叫smustar吧

在smustar下面再写我们模块的主文件就叫smumodule.lua吧

参考官网,我们的模块写法应该是这样子的

module(“LuCI.controller.smustar.smumodule”, package.seeall)

function index()
entry({“admin”, “network”, “802.1x“}, cbi(“smustar-smumodule/netifaces”), “Network interfaces”, 30).dependent=false
end

第一句话是声明一下这个模块了,没什么可说的。

第二句话就是我们模块的主函数,其中呢要告诉它我们的入口,与其说入口,不如说就是告诉它是要admin登录才能用的,是在network这个菜单下,名字呢,叫做802.1x。模块执行的程序呢在smustar-smumodule/netifaces这里。

好了各位又郁闷了smustar-smumodule/netifaces是什么东西,这是我们要建立的另外一个文件,上面不是说要两个么

我们找到路径/usr/lib/lua/LuCI/module

在下面建立文件夹smustar-smmodule建立文件netfaces.lua

好了接下来就是要在netfaces.lua写我们的程序了,参考官网所说的这个什么LuCI最酷的地方,也就是修改config文件

不要说你不懂什么是config文件了,最简单的比如network。

我们在/etc/config下面建立一个配置文件叫smuset吧

那这就是一个config文件的写法

config ‘interface’ ‘smustar’

option ‘user’ ‘youruser’
option ‘pass’ ‘yourpass’

ok这个config文件就是这样子了接下来写netfaces.lua

m = Map(“smuset”, “smustar”) — We want to edit the uci config file /etc/config/smustar 这里是我们要配置的文件了,默认的路径它已经能够区别的,不用管了
s = m:section(TypedSection, “interface”, “smustar”) — Especially the “interface”-sections读出里面的interface区域来
s.addremove = true — Allow the user to create and remove the interfaces

s:option(Value, “user”, “youruser”)这个能就是一个input即一个输入框了读取的是smuset中的user项。youruser是提示语罗

key=s:option(Value, “pass”, “your password”)

key.password=true; 设置为星号的密码输入框

return m — Returns the map
好了文件就完成了,之后我们进入LuCI配置界面

在network下可以看到了802.1x选项

进入后有账号和密码输入框 改一下之后

save&apply一下,发现密码被修改了。我们的802.1x配置界面就做好了!

本文章由http://www.wifidog.pro/2015/07/30/openwrt-luci%E4%BF%AE%E6%94%B9.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整理编辑,转载请注明出处