冥王星的博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

标题:使用 OpenWrt Image Generator 为 WR703N 路由器定制固件

之前试着自己编译固件,编译是成功了,但是在后期安装官方仓库的ipk时出现问题,因为自己编译的固件和官方固件的内核版本号不一样,导致官方仓库的ipk不能安装,即使使用--force-depends参数强制安装也不能成功。

openwrt的内核版本号后边带的一串checksum是根据配置计算出来的,即使使用同官方固件相同版本的源代码编译,只要配置不一样,编译出来的内核版本也是不一样的。
后来发现了 Image Generator,用于把前期编译生成的文件生成刷机用的 bin 文件。编译时的最后部分就是用的这个工具。

从官方仓库直接下载Image Generator,只要运行一个命令就可以生成自己的 bin 文件,并且生成的固件内核版本号与官方固件完成相同。

WiKi在这里:http://wiki.openwrt.org/doc/howto/obtain.firmware.generate

安装操作系统

VMware 10
Ubuntu 14.04.1 x64

配置编译环境

sudo apt-get update
sudo apt-get install subversion build-essential libncurses5-dev zlib1g-dev gawk git ccache gettext libssl-dev xsltproc

下载Image Generator for ar71xx

https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-ImageBuilder-15.05-ar71xx-generic.Linux-x86_64.tar.bz2

建议使用迅雷下载然后拷进去,节约时间

cd ~
mkdir opimagegen && cd opimagegen
wget https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-ImageBuilder-15.05-ar71xx-generic.Linux-x86_64.tar.bz2
tar -xvjf OpenWrt-ImageBuilder-15.05-ar71xx-generic.Linux-x86_64.tar.bz2
cd OpenWrt-ImageBuilder-15.05-ar71xx-generic.Linux-x86_64

配置

根据需要修改repositories.conf

## repositories.conf
## 说明:我把官网的packages文件夹通过代理整个下载到本地目录,所以文件内容改成下面的样子
## 这个文件你也可以不改,保持默认,但是在编译时下载,国内会很慢,还会失败
## Place your custom repositories here, they must match the architecture and version.
# src/gz chaos_calmer http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages
# src custom file:///usr/src/openwrt/bin/ar71xx/packages

## Remote package repositories
src/gz chaos_calmer_base file:/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/base
src/gz chaos_calmer_luci file:/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/luci
src/gz chaos_calmer_packages file:/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/packages
src/gz chaos_calmer_routing file:/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/routing
src/gz chaos_calmer_telephony file:/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/telephony
src/gz chaos_calmer_management file:/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/management

## This is the local package repository, do not remove!
src imagebuilder file:packages

把需要替换固件中的文件放到files目录中,官方固件无线默认是关闭的,为了默认打开无线功能,把无线的配置文件放到files中,在生成固件时就会替换掉默认的文件。

方法是这样的:路由器刷好官方固件,把无线打开,从网页把配置文件备份出来,把需要的文件按固件中的目录结构放到files目录中。

无线配置的文件是wireless,在固件中的路径是 /etc/config/wireless,所以在编译环境中把它放到
files/etc/config/wireless

这是我的wireless配置文件,只是打开了无线功能

$ cat files/etc/config/wireless
config wifi-device  radio0
        option type     mac80211
        option channel  11
        option hwmode   11g
        option path     'platform/ar933x_wmac'
        option htmode   HT20
        # REMOVE THIS LINE TO ENABLE WIFI:
        option disabled 0

config wifi-iface
        option device   radio0
        option network  lan
        option mode     ap
        option ssid     OpenWrt-703N
        option encryption none

生成镜像

用这个命令查看支持的profile

make info

703N对应的配置是TLWR703

编译

make image PROFILE=TLWR703 PACKAGES="libiwinfo libiwinfo-lua liblua libubus-lua libuci-lua lua luci luci-app-firewall luci-base luci-lib-ip luci-lib-nixio luci-mod-admin-full luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap rpcd uhttpd uhttpd-mod-ubus luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES=files/

PROFILE 是从支持列表中找出的路由器型号
PACKAGES 是添加到固件中的包名,如果要从固件中删除包,可以在包名前加 -
FILES 是指定用files目录中的文件替换掉固件中的文件

运行make image PROFILE=TLWR703生成的固件,比官方固件少很多包,比如没有luci,所以我比较了官方固件的包和make image PROFILE=TLWR703生成的固件的包,把缺少的包指定到PACKAGES参数,并且增加了luci-i18n-base-zh-cn和luci-i18n-firewall-zh-cn两个中文包。

生成的固件在 bin 目录中

附录

软件包

  • 与官方固件比较缺少的包
libiwinfo libiwinfo-lua liblua libubus-lua libuci-lua lua luci luci-app-firewall luci-base luci-lib-ip luci-lib-nixio luci-mod-admin-full luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap rpcd uhttpd uhttpd-mod-ubus
  • 中文
luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn
  • Qos
luci-app-qos luci-i18n-qos-zh-cn

命令行升级固件

如果路由器没有luci,则需要通过命令行配置和升级
如果路由器没设置密码,要先telnet上去设置密码
设置好密码了ssh连接到路由器
用scp把固件上传到路由器的/tmp
有两个命令可以升级固件

sysupgrade -n -v /tmp/[specified firmware].bin
mtd -r write /tmp/[specified firmware].bin firmware

我用的是第一个,第二个没用过
-n 不保存配置
-v 输出详细信息

官方固件中安装的软件包

root@OpenWrt:/# opkg list-installed
base-files - 157-r46767
busybox - 1.23.2-1
dnsmasq - 2.73-1
dropbear - 2015.67-1
firewall - 2015-07-27
fstools - 2015-05-24-09027fc86babc3986027a0e677aca1b6999a9e14
hostapd-common - 2015-03-25-1
ip6tables - 1.4.21-1
iptables - 1.4.21-1
iw - 3.17-1
jshn - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.18.20-1-7bed08fa9c06eb8089e82c200340ec66
kmod-ath - 3.18.20+2015-03-09-3
kmod-ath9k - 3.18.20+2015-03-09-3
kmod-ath9k-common - 3.18.20+2015-03-09-3
kmod-cfg80211 - 3.18.20+2015-03-09-3
kmod-crypto-aes - 3.18.20-1
kmod-crypto-arc4 - 3.18.20-1
kmod-crypto-core - 3.18.20-1
kmod-gpio-button-hotplug - 3.18.20-1
kmod-ip6tables - 3.18.20-1
kmod-ipt-conntrack - 3.18.20-1
kmod-ipt-core - 3.18.20-1
kmod-ipt-nat - 3.18.20-1
kmod-ipv6 - 3.18.20-1
kmod-lib-crc-ccitt - 3.18.20-1
kmod-mac80211 - 3.18.20+2015-03-09-3
kmod-nf-conntrack - 3.18.20-1
kmod-nf-conntrack6 - 3.18.20-1
kmod-nf-ipt - 3.18.20-1
kmod-nf-ipt6 - 3.18.20-1
kmod-nf-nat - 3.18.20-1
kmod-nf-nathelper - 3.18.20-1
kmod-nls-base - 3.18.20-1
kmod-ppp - 3.18.20-1
kmod-pppoe - 3.18.20-1
kmod-pppox - 3.18.20-1
kmod-slhc - 3.18.20-1
kmod-usb-core - 3.18.20-1
kmod-usb2 - 3.18.20-1
libblobmsg-json - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libc - 0.9.33.2-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libiwinfo - 2015-06-01-ade8b1b299cbd5748db1acf80dd3e9f567938371
libiwinfo-lua - 2015-06-01-ade8b1b299cbd5748db1acf80dd3e9f567938371
libjson-c - 0.12-1
libjson-script - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
liblua - 5.1.5-1
libnl-tiny - 0.1-4
libubox - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
libubus-lua - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
libuci - 2015-04-09.1-1
libuci-lua - 2015-04-09.1-1
libxtables - 1.4.21-1
lua - 5.1.5-1
luci - git-15.248.30277-3836b45-1
luci-app-firewall - git-15.248.30277-3836b45-1
luci-base - git-15.248.30277-3836b45-1
luci-lib-ip - git-15.248.30277-3836b45-1
luci-lib-nixio - git-15.248.30277-3836b45-1
luci-mod-admin-full - git-15.248.30277-3836b45-1
luci-proto-ipv6 - git-15.248.30277-3836b45-1
luci-proto-ppp - git-15.248.30277-3836b45-1
luci-theme-bootstrap - git-15.248.30277-3836b45-1
mtd - 21
netifd - 2015-06-08-8795f9ef89626cd658f615c78c6a17e990c0dcaa
odhcp6c - 2015-07-13-024525798c5f6aba3af9b2ef7b3af2f3c14f1db8
odhcpd - 2015-05-21-2ebf6c8216287983779c8ec6597d30893b914a7c
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-7
ppp - 2.4.7-6
ppp-mod-pppoe - 2.4.7-6
procd - 2015-08-16-0da5bf2ff222d1a499172a6e09507388676b5a08
rpcd - 2015-05-17-3d655417ab44d93aad56a6d4a668daf24b127b84
swconfig - 10
uboot-envtools - 2014.10-2
ubox - 2015-07-14-907d046c8929fb74e5a3502a9498198695e62ad8
ubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
ubusd - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
uci - 2015-04-09.1-1
uhttpd - 2015-08-17-f91788b809d9726126e9cf4384fedbbb0c5b8a73
uhttpd-mod-ubus - 2015-08-17-f91788b809d9726126e9cf4384fedbbb0c5b8a73
usign - 2015-05-08-cf8dcdb8a4e874c77f3e9a8e9b643e8c17b19131
wpad-mini - 2015-03-25-1

make image PROFILE=TLWR703 生成的固件中安装的软件包

# make image PROFILE=TLWR703
root@OpenWrt:/# opkg list-installed
base-files - 157-r46767
busybox - 1.23.2-1
dnsmasq - 2.73-1
dropbear - 2015.67-1
firewall - 2015-07-27
fstools - 2015-05-24-09027fc86babc3986027a0e677aca1b6999a9e14
hostapd-common - 2015-03-25-1
ip6tables - 1.4.21-1
iptables - 1.4.21-1
iw - 3.17-1
jshn - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.18.20-1-7bed08fa9c06eb8089e82c200340ec66
kmod-ath - 3.18.20+2015-03-09-3
kmod-ath9k - 3.18.20+2015-03-09-3
kmod-ath9k-common - 3.18.20+2015-03-09-3
kmod-cfg80211 - 3.18.20+2015-03-09-3
kmod-crypto-aes - 3.18.20-1
kmod-crypto-arc4 - 3.18.20-1
kmod-crypto-core - 3.18.20-1
kmod-gpio-button-hotplug - 3.18.20-1
kmod-ip6tables - 3.18.20-1
kmod-ipt-conntrack - 3.18.20-1
kmod-ipt-core - 3.18.20-1
kmod-ipt-nat - 3.18.20-1
kmod-ipv6 - 3.18.20-1
kmod-lib-crc-ccitt - 3.18.20-1
kmod-mac80211 - 3.18.20+2015-03-09-3
kmod-nf-conntrack - 3.18.20-1
kmod-nf-conntrack6 - 3.18.20-1
kmod-nf-ipt - 3.18.20-1
kmod-nf-ipt6 - 3.18.20-1
kmod-nf-nat - 3.18.20-1
kmod-nf-nathelper - 3.18.20-1
kmod-nls-base - 3.18.20-1
kmod-ppp - 3.18.20-1
kmod-pppoe - 3.18.20-1
kmod-pppox - 3.18.20-1
kmod-slhc - 3.18.20-1
kmod-usb-core - 3.18.20-1
kmod-usb2 - 3.18.20-1
libblobmsg-json - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libc - 0.9.33.2-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libjson-c - 0.12-1
libjson-script - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libnl-tiny - 0.1-4
libubox - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
libuci - 2015-04-09.1-1
libxtables - 1.4.21-1
mtd - 21
netifd - 2015-06-08-8795f9ef89626cd658f615c78c6a17e990c0dcaa
odhcp6c - 2015-07-13-024525798c5f6aba3af9b2ef7b3af2f3c14f1db8
odhcpd - 2015-05-21-2ebf6c8216287983779c8ec6597d30893b914a7c
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-7
ppp - 2.4.7-6
ppp-mod-pppoe - 2.4.7-6
procd - 2015-08-16-0da5bf2ff222d1a499172a6e09507388676b5a08
swconfig - 10
uboot-envtools - 2014.10-2
ubox - 2015-07-14-907d046c8929fb74e5a3502a9498198695e62ad8
ubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
ubusd - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
uci - 2015-04-09.1-1
usign - 2015-05-08-cf8dcdb8a4e874c77f3e9a8e9b643e8c17b19131
wpad-mini - 2015-03-25-1

下载官方软件仓库到本地

wget --mirror --no-parent https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/

快速架设http服务器

之前下载软件仓库到本地,目录结构是这样的:

/home/noright/downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/

运行这个命令就可以快速开始一个http服务器

cd ~/downloads.openwrt.org
python -m SimpleHTTPServer 8000

通过网页修改路由器的软件包配置,就可以使用本地软件仓库了

dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
src/gz chaos_calmer_base http://192.168.1.115:8000/chaos_calmer/15.05/ar71xx/generic/packages/base
src/gz chaos_calmer_luci http://192.168.1.115:8000/chaos_calmer/15.05/ar71xx/generic/packages/luci
src/gz chaos_calmer_packages http://192.168.1.115:8000/chaos_calmer/15.05/ar71xx/generic/packages/packages
src/gz chaos_calmer_routing http://192.168.1.115:8000/chaos_calmer/15.05/ar71xx/generic/packages/routing
src/gz chaos_calmer_telephony http://192.168.1.115:8000/chaos_calmer/15.05/ar71xx/generic/packages/telephony
src/gz chaos_calmer_management http://192.168.1.115:8000/chaos_calmer/15.05/ar71xx/generic/packages/management
option check_signature 1
posted on 2015-11-05 09:32  №冥王星  阅读(4311)  评论(0编辑  收藏  举报