1、 安裝環境
Linux系統,如果在CentOS上操作,需安裝如下依賴包:
yum install binutils bzip2 gawk gcc gcc-c++ gettext makencurses-devel patch unzip wget zlib-devel
yum install subversion screen
2、 下載OpenWRT源碼
mkdir /usr/src/test
cd /usr/src/test
svn co svn://svn.openwrt.org/openwrt/trunk (開發版本,不穩定,不建議下載)
wget http://downloads.openwrt.org/bac ... 0.03_source.tar.bz2(目前穩定版本,建議)
3、 檢查配置環境
必須使用非root用戶進行操作,添加一個普通用戶。(注意:如果使用root進行操作的話,會提示檢查失敗:Checking 'non-root'...failed.)
[root@localhost trunk]# adduser openwrt
[root@localhost trunk]# su openwrt
為了防止文件讀寫權限造成問題,需要將源碼copy到openwet的根目錄下進行所有操作。
[openwrt@localhost openwrt]$ cd ~
[openwrt@localhost ~]$ cp -r /usr/src/test/trunk ./
[openwrt@localhost ~]$ cd trunk/
[openwrt@localhost trunk]$ ls
BSDmakefile LICENSE README feeds.conf.default package scripts toolchain
Config.in Makefile docs include rules.mk target tools
4、 下載feeds
Feeds是OpenWrt環境所需要的軟件包套件。最重要的feeds有:
‘packages’一些額外的基礎路由器特性軟件
‘LuCI’OpenWrt默認的GUI
‘Xwrt’另一種可選的GUI界面
需要能夠連接互聯網。
在下載之前可以通過查看’feeds.conf.default’文件,來檢查哪些文件需要包含在環境中。
開始下載,使用:
[openwrt@localhost trunk]$ ./scripts/feeds update -a
安裝feeds包,只有安裝之后,在后面的makemenuconfig時,才可以對相關配置進行勾選。
[openwrt@localhost trunk]$ ./scripts/feeds install -a
如果更新了feeds的配置文件,需要添加新的軟件包用於生成系統。只需進行重復操作:
[openwrt@localhost trunk]$ ./scripts/feeds update -a
[openwrt@localhost trunk]$ ./scripts/feeds install -a
5、 進行配置
編譯過程使用的交叉編譯,交叉編譯生成的SDK以及image等文件的類型取決於開發環境、應用硬件、以及源碼版本。所以要對自己的環境進行了解,才能進行正確的配置。我在配置過程中,就遇到了這個問題,我的硬件是brcm47xx,在第一次編譯的時候,選擇地是Target System(Broadcom BCM947xx/953xx),最后生成的包無法在router上安裝,版本不匹配。第二次安裝時,選擇了Target System (Broadcom BCM947xx/953xx[2.4]),安裝成功,我的板子可能只支持linux2.4的內核。(設備型號是Linksys Wrt54gs v3.0) (2011.05.01添加:其實LinksysWrt54gs v3.0是支持Linux 2.6版本的,TargetSystem 選擇 Broadcom BCM947xx/953xx,編譯后也是可以用的,這周末由於項目需要改某個軟件,每次修改代碼后,都得重新編譯一下固件,經過來回編譯了十來次,都可以使用。另外。內核版本升級之后,無線驅動改成了mac802.11,而非以前的wl,以為wl.o這個專門的庫只在linux2.4中才用到。)
[openwrt@localhost trunk]$ make defconfig
[openwrt@localhost trunk]$ make prereq
[openwrt@localhost trunk]$ make menuconfig
通過文本對話框進行選項配置,最主要的配置項有:
Target system(目標系統類型)
Package selection(軟件包選擇)
Build system settings (編譯系統設置)
Kernel modules (內核模塊)
- 表示:這個包裹選中編譯,並安裝在firmware中;
[M]表示:這個軟件包選中編譯,但並不安裝在firmware中。
在退出Menuconfig的時,會提示是否保存配置。
在此我只對target system進行了選擇;勾選了Advancedconfiguration option和Build the OpenWrt SDK選項。
6、 編譯
(1)一般情況,使用一個簡單的命令:
[openwrt@localhost trunk]$ make
(2)在多核處理器系統上為提高速度,可使用(例如用3核處理器):
[openwrt@localhost trunk]$ make –j 3
(3)在后台進行編譯,使用空閑的I/O資源和CPU性能,可使用(例如使用雙核處理器)
[openwrt@localhost trunk]$ onice -c 3 nice -n 20 make -j 2
(4)編譯一個單獨的軟件包(例如在cups軟件包):
[openwrt@localhost trunk]$ make package/cups/compile V=99
(5)如果特殊原因需要分析編譯報錯信息:
[openwrt@localhost trunk]$ make V=99 2>&1 |teebuild.log |grep -i error
說明:將編譯的所有輸出信息保存在build.log中,將error信息打印在屏幕上。
(6)一個復雜指令的應用
[openwrt@localhost trunk]$ ionice -c 3 nice -n 20 make -j 2V=99 CONFIG_DEBUG_SECTION_MISMATCH=y 2>&1 \|tee build.log |egrep -i'(warn|error)'
說明:將編譯的所有輸出信息保存在build.log中,將error和warning信息打印在屏幕上。編譯過程使用雙核CPU,占用后台資源。
7、 生成鏡像(Image)位置
新生成的鏡像會默認放在新建的一個bin目錄下。例如:/bin/brcm-2.4/packages
[openwrt@localhost trunk]$ls bin/*
將編譯好的鏡像做個備份,例如備份到/目錄下:
[openwrt@localhost trunk]$cp bin /
8、 清理工作
建議現在清理編譯產生的文件,以免下次編譯時造成沖突,(文件如果存在的話,將不會被替換),執行makeclean
注意:在執行clean命令,確保已經將編譯好的image進行了備份。清理工作會清楚bin目錄。
[openwrt@localhost trunk]$make clean
除了清除生成的目錄,還想清除交叉編譯工具(以及工具鏈目錄)
[openwrt@localhost trunk]$make dirclean
清除所有相關的東西,包括下載的軟件包,配置文件,feed內容等:(不建議使用)
[openwrt@localhost trunk]$make distclean
對於更新feeds后出現的錯誤:
ERROR:please fixpackage/feeds/packages/mc/Makefile 等類似的問題,需要執行這條語句進行系統的清理
9、 安裝OpenWrt
找到對應的固件,進行固件升級。網上方法很多,這里不再贅述。
后續會推出在OpenWrt上的開發文檔:)