编译自己的openwrt固件

编译openwrt的过程只能用纠结两个字形容,不说make menuconfig里那繁多的选项让人头晕眼花,第一次编译真是让人崩溃,编译一次要几个小时,再编译有问题时,make clean一下再编译又是几个小时,着实让人崩溃。不过自己编译的过程还是挺有趣的。再也不必等待别人的固件啦,给我源码,自己动手,丰衣足食,不知道以后有没有机会弄弄openwrt开发。安装openwrt的开发环境、svn获取源码、修改feeds、自定义设置等等,为了方便自己也为了方便大家,写了一个一键开发脚本,安装必要的软件包,svn下载各个branch的源码,修改一些自定义设置,增加对HG255D的编译支持等等。

话不多说,直接上源码:

code-area
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# !/bin/bash
# description:one-key install openwrt SDK environment.add some packages feeds include shadowsocks chinaDNS etc.
# 2015-1-30 ver 1.0
# Tyr Chen @ http://www.chenhd.com
set -e
if [ "$UID" -eq "0" ];then
echo "please do not run this shell as root.exit."
exit 1
fi
read -p "please input the dir where you want to install:" opdir
if [ -d $opdir -a -w $opdir ];then
echo "select $opdir"
else
echo "$opdir not exists,try create"
mkdir -p $opdir &&echo "create success" || echo "create failure"
fi
# install prerequisites and their corresponding packages
sudo apt-get update
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf \
gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term \
zlib1g-dev git gawk libssl-dev -y
cd $opdir
go() # function of alter feeds,add packages,customed settings,add HG255D compile support etc.only implement to trunk.
{
# svn checkout svn://svn.openwrt.org/openwrt/trunk
# git clone git://git.openwrt.org/openwrt.git
# cd trunk
# cd openwrt
################# add feeds and packages ####################
# include rygel,shadowsocks,chinaDNS,shadownVPN,redsocks2,etc.
echo "
src-git luci2 git://git.openwrt.org/project/luci2/ui.git
src-git ramod git://github.com/ravageralpha/my_openwrt_mod.git
src-git ChinaDNS https://github.com/clowwindy/ChinaDNS.git " >> feeds.conf.default
sed -i '1i src-git rygel https://github.com/aandyl/openwrt-packages.git;rygel' feeds.conf.default
git clone https://github.com/aa65535/openwrt-dist-luci.git package/openwrt-dist-luci
git clone https://github.com/shadowsocks/openwrt-shadowsocks.git package/shadowsocks-libev
################ update and install feeds ###################
./scripts/feeds update -a
./scripts/feeds install -a
############### add Huawei HG255D support ##################
sed -i '/HG255D/s/# //g' target/linux/ramips/image/Makefile
# support HG255D LED
sed -i '/ramips_board_name/a \
hg255d)\
status_led="hg255d:power" \
;;' target/linux/ramips/base-files/etc/diag.sh
############## customed setting #############################
# wifi-encryption & password
sed -i -e 's/none/psk2/' -e '/encryption/a option key 11223344' package/kernel/mac80211/files/lib/wifi/mac80211.sh
# language & themes
sed -i 's/auto/zh_cn/;s/openwrt.org/bootstrap/' feeds/luci/modules/luci-base/root/etc/config/luci
sed -i '/internal languages/a \
option zh_cn chinese \
option en English ' feeds/luci/modules/luci-base/root/etc/config/luci
sed -i '/internal themes/a \
option Bootstrap /luci-static/bootstrap' feeds/luci/modules/luci-base/root/etc/config/luci
# alter net.netfilter.nf_conntrack_max from 16384 to 65535
sed -i 's/16384/65535/' package/base-files/files/etc/sysctl.conf
# timezone
sed -i -e '/UTC/a option zonename Asia/Shanghai' -e 's/UTC/CST-8/' package/base-files/files/etc/config/system
read -p "add HG255D led configuration to package/base-files/files/etc/config/system ?
if yes, answer yes,otherwise leave blank:" ANS
if [ $ANS = 'yes' ];then
echo "
config led 'usb_led'
option name 'USB'
option sysfs 'hg255d:usb'
option trigger 'usbdev'
option dev '1-1'
option interval '50'
config led 'wlan_led'
option name 'WLAN'
option sysfs 'hg255d:wlan'
option trigger 'netdev'
option dev 'ra0'
option mode 'link tx'
config led 'internet_led'
option name 'INTERNET'
option sysfs 'hg255d:internet'
option trigger 'netdev'
option dev 'eth0.2'
option mode 'tx rx'
" >> package/base-files/files/etc/config/system
fi
echo "done.Bye"
exit 0
}
read -p "please choose which branch you want to download:
branch code
trunk (main development tree) A
14.07 branch 'Barrier Breaker' B
12.09 branch 'Attitude Adjustment' C
10.03 branch 'Backfire' D
8.09 branch 'Kamikaze' E
7.09 branch 'Kamikaze' F
Tagged G
openwrt-pandorabox H
ps:this shell's function of feeds add&update&install&alter,customed settings,
HG255D support only implement in trunk branchother branch not support yet.
choose which one(input the code right side):" CODE
case $CODE in
"A")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/trunk/
cd trunk
go
;;
"B")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/branches/barrier_breaker
;;
"C")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/branches/attitude_adjustment
;;
"D")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/branches/backfire
;;
"E")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/branches/8.09
;;
"F")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/tags/kamikaze_7.09
;;
"G")
echo "start clone ..."
svn co svn://svn.openwrt.org/openwrt/tags/backfire_10.03
;;
"H")
echo "start clone ..."
svn co svn://svn.openwrt.org.cn/dreambox/trunk openwrt-pandorabox
;;
*)
echo "start clone ..."
echo "error code"
exit 2
esac
echo "download ok.Bye"
exit 0

运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# please choose which branch you want to download:
# branch code
trunk (main development tree) A
14.07 branch 'Barrier Breaker' B
12.09 branch 'Attitude Adjustment' C
10.03 branch 'Backfire' D
8.09 branch 'Kamikaze' E
7.09 branch 'Kamikaze' F
Tagged G
openwrt-pandorabox H
# ps:this shell's function of feeds add&update&install&alter,customed settings,
# HG255D support only implement in trunk branchother branch not support yet.
choose which one(input the code right side):

最近在这上面花的时间有点多,几个固件编译完应该相当长的时间里都不会再碰了。

如果您觉得这篇文章对您有帮助,不妨支持我一下!