Openwrt编译进阶
(1)-编译703_8M固件
1. target/linux/ar71xx/image/Makefile
1 |
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWR703,tl-wr703n-v1,TL-WR703N,ttyATH0,115200,0×07030101,1,8Mlzma)) |
2. tools/firmware-utils/src/mktplinkfw.c
1 2 3 4 |
.id = "TL-WR703Nv1", .hw_id = HWID_TL_WR703N_V1, .hw_rev = 1, .layout_id = "4Mlzma", |
将其中的4Mlzma替换成8Mlzma
(2)-修改默认WIFI,添加WIFI配置,WIFI名为MAC后六位
修改package/kernel/mac80211/files/lib/wifi/mac80211.sh
option disabled 1改成0,默认开启wifi。
1 2 3 4 5 |
option htmode HT40+ option channel 1 option country CN option noscan 1 option txpower 17 |
option htmode HT40+ 使用40MHz频宽,但只支持1-7信道。HT40-,支持5-13信道。HT20 支持1-13信道,20MHz频宽
option channel 1使用信道1,1-13之间。若有限定频宽,信道参考如上。
option country CN 设定wifi标准为中国 CN、JP、HK均可开启13信道,默认的US只有1-12信道
option noscan 1 强制使用40MHz的频宽
option txpower 17 发射功率为17dBm,大约50mW。不可设定过大,否则有烧毁PA的危险。
修改默认SSID:
1 2 3 4 5 6 7 |
config wifi-iface option device radio$devidx option network lan option mode ap option ssid OpenWrt_$(cat /sys/class/ieee80211/${dev}/macaddress|awk -F ":" '{print $4""$5""$6 }'| tr a-z A-Z) option encryption psk2 option key 12369874 |
(3)-添加root帐号密码
修改package/base-files/files/etc/shadow文件
1 |
root::0:0:99999:7::: |
改成(密码是admin)
1 |
root:$1$21u5EotL$B9ebsVgEQe.C7lsk0iMf10:0:0:99999:7::: |
注:生成加密的密码字段的方法:
方法一(交互式)
命令格式:
1 2 3 |
openssl passwd -1 -salt $(< /dev/urandom tr -dc '[:alnum:]' | head -c 32) Password: # input your password here $1$MZrDxgEw$i2XBgmDMo0Wf1.OVvOGGQ1 |
方法二(适用于脚本)
命令格式:
1 2 |
echo "xansun" | openssl passwd -1 -salt $(< /dev/urandom tr -dc '[:alnum:]' | head -c 32) -stdin $1$KsRJO8kG$M9co4G7T6.5KcITsSCRNS/ |
(4)-修改路由连接数,优化网络参数
修改路由连接数,优化网络参数
连接数默认情况下是1.6万多吧。可以选择性修改。
修改sysctl.conf文件,位于package/base-files/files/etc/
1 |
net.netfilter.nf_conntrack_max=65535 |
(5)-默认中文,修改主机名,添加并修改默认主题,设定时区
默认中文
修改/feeds/luci/modules/luci-base/root/etc/config/luci
1 |
option lang auto改为option lang zh_cn |
并在config internal languages下添加
1 2 |
option en 'English' option zh_cn 'chinese' |
修改/package/base-files/files/etc/config/system
1 2 3 4 5 6 7 8 9 10 11 12 |
config system option hostname 'OpenWrt' option conloglevel '8' option cronloglevel '8' option zonename 'Asia/Shanghai' option timezone 'CST-8' config timeserver ntp list server 0.openwrt.pool.ntp.org list server 1.openwrt.pool.ntp.org list server 2.openwrt.pool.ntp.org list server 3.openwrt.pool.ntp.org option enable_server 0 |
修改默认Lan ip
修改package/base-files/files/lib/functions/uci-defaults.sh中
1 |
set network.lan.ipaddr='192.168.1.1' |
修改默认端口
修改/package/network/services/uhttpd/files/uhttpd.config 此处为修改默认端口位置
修改以后要install -a
-默认启动DHCP
/package/network/services/dnsmasq/files/dhcp.conf
1 2 3 4 5 6 |
config dhcp lan option interface lan option start 100 option limit 150 option leasetime 12h option ignore 0 -----------------添加这个 |
(6)-添加aria2,luci添加,web管理界面添加
aria2的源码来自于
http://sourceforge.net/projects/aria2/files/stable/
我们这里以aria2-1.17.1版本为例下载的源码格式为aria2-1.17.1.tar.bz2
aria2的依赖安装
很多人没安装这依赖编译时会报错的
sudo apt-get update
sudo apt-get install autoconf automake libcppunit-dev autopoint openssl libtool sphinx-common sphinxsearch libgcrypt11-dev libxml2-dev pkg-config
开始集成aria2c
首先把下载下来的aria2-1.17.1.tar.bz2放进openwrt源码根目录的dl目录
获取md5码
ctrl+alt+T弹出终端输入
md5sum /……/……/trunk/dl/aria2-1.17.1.tar.bz2 省略好代表openwrt的源码的路径补全,回车就能获取md5码,记住用用的
在/feeds/packages/net/aria2/路径下创建aria2c源码的makefile文件内容如下 (make文件及其他本文需要文件见文章最下方)
#
# Copyright (C) 2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=aria2 名字
PKG_VERSION:=1.17.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=
PKG_MD5SUM:=86229ef8d289893934cb3af25c8fddf6
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
define Package/aria2
SECTION:=net
CATEGORY:=Network
SUBMENU:=File Transfer
TITLE:=lightweight download utility
URL:=http://aria2.sourceforge.net/
DEPENDS:=+libopenssl +zlib +libxml2 +libstdcpp \
$(INTL_DEPENDS) $(ICONV_DEPENDS)
endef
define Package/aria2/description
aria2 is a lightweight multi-protocol & multi-source command-line download
utility
endef
define Package/aria2/conffiles
/etc/config/aria2
endef
CONFIGURE_ARGS += \
–disable-nls \
–without-gnutls \
–without-libnettle \
–without-libgmp \
–without-libgcrypt \
–without-libexpat \
–without-libcares \
–without-sqlite3 \
–with-openssl \
–with-libxml2 \
–with-libz
CONFIGURE_VARS += \
ZLIB_CFLAGS=”-I$(STAGING_DIR)/usr/include” \
ZLIB_LIBS=”-L$(STAGING_DIR)/usr/lib”
define Package/aria2/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/aria2c $(1)/usr/bin
endef
$(eval $(call BuildPackage,aria2))
在feeds目录下面找到packages.index索引文件,添加aria2源码索引记录
双击打开packages.index,在任意位置添加如下代码
Source-Makefile: feeds/packages/net/aria2/Makefile
Package: aria2
Submenu: File Transfer
Version: 1.17.1-1
Depends: +libc +USE_EGLIBC:librt +USE_EGLIBC:libpthread +libopenssl +zlib +libxml2 +libstdcpp
Menu-Depends:
Provides:
Section: net
Category: Network
Title: lightweight download utility
Maintainer: OpenWrt Developers Team <[email protected]>
Source: aria2-1.17.1.tar.bz2
Type: ipkg
Description: aria2 is a lightweight multi-protocol & multi-source command-line download
utility
http://aria2.sourceforge.net/
OpenWrt Developers Team <[email protected]>
@@
到这里aria2算是添加完了,用命令还可以使用,没luci界面是有点不方便,下面完美来添加luci-aria2
添加luci-aria2
文章末有我上传的luci-aria2的源码文件,下载下来后放到你的luci响应的目录,版本不宜样目录可能不宜样
trunk版本为例
把luci-aria2这个文件夹放进/trunk/feeds/luci/applications/这个目录里面
然后在trunk/feeds/目录下找到luci.index 这个索引文件,打开在任意位置添加如下代
Package: luci-app-aria2
Submenu: 3. Applications
Version: 0.11+svk-1
Depends: +libc +USE_EGLIBC:librt +USE_EGLIBC:libpthread +PACKAGE_luci-app-aria2:aria2
Menu-Depends:
Provides:
Build-Depends: lua/host
Section: luci
Category: LuCI
Title: aria2 configuration module
Maintainer: LuCI Development Team <[email protected]>
Source:
Type: ipkg
Description: aria2 configuration module http://luci.subsignal.org/ LuCI Development Team <[email protected]>
@@
保存退出即可
到这里就集成完了
最后在终端执行
./scripts/feeds install -a
make menuconfig
就可以在luci>3. Applications 找到luci-app-aria2了
(7)-添加fullflash分区,uboot、art分区可写
修改target/linux/ar71xx/files/drivers/mtd/tplinkpart.c
#define TPLINK_NUM_PARTS 5
改为
#define TPLINK_NUM_PARTS 6
(即在原有的数值上加1)
然后在文件中找到以下内容
parts[0].name = “u-boot”;
parts[0].offset = 0;
parts[0].size = offset;
parts[0].mask_flags = MTD_WRITEABLE;
parts[1].name = “kernel”;
parts[1].offset = offset;
parts[1].size = rootfs_offset – offset;
parts[2].name = “rootfs”;
parts[2].offset = rootfs_offset;
parts[2].size = art_offset – rootfs_offset;
parts[3].name = “art”;
parts[3].offset = art_offset;
parts[3].size = TPLINK_ART_LEN;
parts[3].mask_flags = MTD_WRITEABLE;
parts[4].name = “firmware”;
parts[4].offset = offset;
parts[4].size = art_offset – offset
在 parts[4].size = art_offset – offset 后面换一行,添加这段
parts[5].name = “fullflash”;
parts[5].offset = 0;
parts[5].size = master->size
uboot、art分区可写,目的是使用ttl刷新uboot、art
注释掉 parts[0].mask_flags = MTD_WRITEABLE;
(8)-顶部菜单添加按钮
比如在顶部菜单添加释放内存按钮
修改/modules/admin-full/luasrc/controller/admin/index.lua
+ entry({“admin”, “Free_Memory”}, call(“Free_Memory”), _(“Free Memory”), 81)
+function Free_Memory()
+
+ luci.util.exec(“echo 3 > /proc/sys/vm/drop_caches”)
+ luci.http.redirect(luci.dispatcher.build_url(“admin”, “status”, “overview”))
+end
(9)-添加一键无线
在如下位置新建一个文件,文件名为01onoff
/target/linux/ar71xx/base-files/etc/hotplug.d/button/01onoff
内容如下:
#!/bin/sh
[ “$BUTTON” = “wps” ]&& [ “$ACTION” = “pressed” ] && {
SW=$(uci get wireless.@wifi-device[0].disabled)
[ $SW == ‘0’ ] && uci setwireless.@wifi-device[0].disabled=1
[ $SW == ‘0’ ] || uci setwireless.@wifi-device[0].disabled=0
wifi
}
保存后设置权限为0777
(10)-添加 3322 DDNS 动态域名解析
/feeds/packages/net/ddns-scripts/files/usr/lib/ddns/services
添加
“3322.org” “http://[USERNAME]:[PASSWORD]@members.3322.org/dyndns/update?system=dyndns&hostname=[DOMAIN]&myip=[IP]&wildcard=OFF”
修改配置项
/feeds/packages/net/ddns-scripts/files/etc/config/ddns
config service “myddns”
option enabled “1”
option service_name “3322.org”
option domain “xxxx.3322.org”
(11)-修改防火墙添加开放端口
/package/firewall/files/firewall.config
添加内容:
config ‘rule’
option ‘target”ACCEPT’
option ‘_name’ ‘tr’
option ‘src’ ‘wan’
option ‘proto”tcpudp’
option ‘dest_port”51413’
config ‘rule’
option ‘target”ACCEPT’
option ‘_name”9091’
option ‘src’ ‘wan’
option ‘proto’ ‘tcp’
option ‘dest_port”9091’
(12)-修改Transmission配置文件
/feeds/packages/net/transmission/files/transmission.config
修改内容:
option rpc_authentication_required true
option umask 0