0x00 安裝依賴
安裝git以下載OpenWrt源碼。安裝編譯工具以進行交叉編譯:
sudo apt-get update sudo apt-get install build-essential subversion git-core libncurses5-dev zlib1g-dev gawk flex quilt libssl-dev xsltproc libxml-parser-perl mercurial bzr ecj cvs unzip
feeds中的部分軟件包可能只能通過subversion (縮寫: svn)或者mercurial下載源代碼。如果你需要安裝這些軟件包,你同時也應當安裝svn和mercurial:
sudo apt-get install subversion mercurial
通過git來下載OpenWrt bleeding edge(trunk版本) 詳情參考https://wiki.openwrt.org/doc/howto/buildroot.exigence 這里我編譯是的15.05
git clone git://github.com/openwrt/openwrt.git
15.05 branch (Chaos Calmer)
git clone -b chaos_calmer git://github.com/openwrt/chaos_calmer.git
14.07 branch (Barrier Breaker)
git clone -b barrier_breaker git://github.com/openwrt/archive.git
0x01 安裝Feeds
此處就是下載一些你之后要編譯進firmware里的一些軟件。若有自己需要額外添加的組件,可以通過添加feeds來實現。比如,我需要添加openvswitch的支持,在目錄下輸入如下命令:
echo 'src-git openvswitch git://github.com/schuza/openvswitch.git' >> feeds.conf.default
然后,更新下載feeds組件包並安裝:
./scripts/feeds update -a //更新下載全部軟件包./scripts/feeds update [包名]) //單獨更新下載某軟件包 ./scripts/feeds install -a //安裝全部軟件包./scripts/feeds install [包名] //單獨安裝某軟件包
0x02 配置OpenWRT
直接在 [openwrt主目錄] 下輸入命令 make menuconfig 即可開始自定義選擇組件
Target System --> 選擇路由器CPU
Target Profile --> 選擇路由器型號
LuCI --> Modules --> <*> luci-base.........LuCI core libraries 然后進入下面的Translations --> 選擇語言
添加LuCI界面
LuCI --> Collections --> <*> luci
添加UTF-8編碼
Kernel modules --> Native Language Support --> <*> kmod-nls-utf8
若之前添加過自己的組件,就對應選擇上,否則編譯不進去!
全部選擇完,一定記住保存,才能成功寫入 .config 文件。
設置LuCI默認語言
打開 feeds/luci/modules/luci-base/root/etc/config/luci 文件
config core main option lang auto //此處修改為option lang zh_cn option mediaurlbase /luci-static/bootstrap option resourcebase /luci-static/resources config extern flash_keep option uci "/etc/config/" option dropbear "/etc/dropbear/" option openvpn "/etc/openvpn/" option passwd "/etc/passwd" option opkg "/etc/opkg.conf" option firewall "/etc/firewall.user" option uploads "/lib/uci/upload/" config internal languages option zh_cn chinese //新增 option en English //新增 config internal sauth option sessionpath "/tmp/luci-sessions" option sessiontime 3600 config internal ccache option enable 1 config internal themes
設置默認開啟WIFI
打開 package/kernel/mac80211/files/lib/wifi/mac80211.sh 文件
0x04 編譯前注意事項
修改固件大小
我的路由器型號WL841N_V8(硬件方面改裝成16M的Flash),所以需要把默認的4M改成了16M,這樣編譯后就沒問題了。
修改 target/linux/ar71xx/image/Makefile 文件,搜索 tl-wr841n-v8
修正網口順序問題
OpenWRT的網口經常是反過來的,所以要進行修正
打開 /openwrt/target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr841n-v8.c 文件
ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
改為
ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
ath79_switch_data.phy_poll_mask = BIT(0);
改為
ath79_switch_data.phy_poll_mask = BIT(4);
ath79_eth0_data.phy_mask = BIT(0);
改為
ath79_eth0_data.phy_mask = BIT(4);
修改LED燈順序問題
打開 target/linux/ar71xx/base-files/etc/uci-defaults/01_leds 文件,修改為如圖所示
0x05 編譯固件
一般情況下,編譯直接在 [openwrt主目錄] 下輸入命令 make V=99 。可以查看編譯過程具體信息。直接make無具體信息。編譯完成后,在bin目錄下就可以找到你編譯好的bin文件,以及bin/packages下編譯好的一些ipk文件,ipk文件可以直接安裝於刷好的OpenWRT中。
注意:此處千萬不要以root權限執行make,否則報N多錯誤。
另附一些編譯選項:
- 在多核電腦中編譯,常規用法為【 cpu處理器的數目 + 1】– 例如使用3進程來編譯 (即雙核CPU), 命令及參數: make -j 3 。這樣可以加速編譯,不過我沒試過。
- 后台編譯,你還在忙其他,不想讓編譯耗費太多資源,只使用一些空閑的I/O和CPU能力來編譯: ionice -c 3 nice -n19 make -j 2
- 單獨編譯某個包: make package/[包名]/compile V=99 。編完后在bin/packages下會找到對應的ipk文件。
- 單獨編譯某個包: make package/[包名]/compile V=99 。編完后在bin/packages下會找到對應的ipk文件。
0x06 參考鏈接