我的機器主系統是Windows 7,用於op開發裝了VirtualBox和Ubuntu 12.04 LTS。
首先,解決依賴問題,開發op必備如下組件。
#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
接下來下載源代碼,需要用到svn工具,下載最新開發版代碼命令如下:
#svn co svn://svn.openwrt.org/openwrt/trunk
因源碼隨時可能變動,下載後,運行snv up更新本地代碼。
下載後一般額外軟件包需要更新:
#./scripts/feeds update -a
# ./scripts/feeds install -a
編譯必須保證有良好的網絡連接,且非root賬戶。
下一步是檢查編譯環境:
#make defconfig
若defconfig回顯提示缺少軟件包或編譯庫等依賴,則按提示安裝所缺軟件包或庫等即可
接下來是配置:
#make menuconfig
比如:
編譯一個mr3420的固件
1.Target System—–選擇Atheros AR71xx/AR7240/AR913x/AR934x
2.Target Profile—-選擇TP-LINK TL-MR3420 v1
3.LuCI—-選擇Collections—– <*> luci
4.LuCI—-選擇Translations—-<*> luci-i18n-chinese
5.Exit—-Yes
6.開始編譯make V=99,最後會得到一個4M的帶中文luci的mr3420固件。
MR3420的8M固件編譯方法
1.在路徑 /trunk/tools/firmware-utils/src/mktplinkfw.c 這個文件裡邊有個“fw max len”,默認3c0000是4M的,請改成7c0000 (這一步把固件最大限制改成8M),如果是16mflash,請改成fc0000(最大限制改成16m)。
2、修改target/linux/ar71xx/files/arch/mips/ar71xx/mach-tl-wr841n.c(找相應文件)
4M:
41 .name = "u-boot",
42 .offset = 0,
43 .size = 0x020000,
44 .mask_flags = MTD_WRITEABLE,
45 }, {
46 .name = "kernel",
47 .offset = 0x020000,
48 .size = 0x140000,
49 }, {
50 .name = "rootfs",
51 .offset = 0x160000,
52 .size = 0x290000,
53 }, {
54 .name = "art",
55 .offset = 0x3f0000,
56 .size = 0x010000,
57 .mask_flags = MTD_WRITEABLE,
58 }, {
59 .name = "firmware",
60 .offset = 0x020000,
61 .size = 0x3d0000,
62 }
63 };
8M::
41 .name = "u-boot",
42 .offset = 0,
43 .size = 0x020000,
44 .mask_flags = MTD_WRITEABLE,
45 }, {
46 .name = "kernel",
47 .offset = 0x020000,
48 .size = 0x140000,
49 }, {
50 .name = "rootfs",
51 .offset = 0x160000,
52 .size = 0x690000,
53 }, {
54 .name = "art",
55 .offset = 0x7f0000,
56 .size = 0x010000,
57 .mask_flags = MTD_WRITEABLE,
58 }, {
59 .name = "firmware",
60 .offset = 0x020000,
61 .size = 0x7d0000,
62 }
63 };
16M::
41 .name = "u-boot",
42 .offset = 0,
43 .size = 0x020000,
44 .mask_flags = MTD_WRITEABLE,
45 }, {
46 .name = "kernel",
47 .offset = 0x020000,
48 .size = 0x140000,
49 }, {
50 .name = "rootfs",
51 .offset = 0x160000,
52 .size = 0xe90000,
53 }, {
54 .name = "art",
55 .offset = 0xff0000,
56 .size = 0x010000,
57 .mask_flags = MTD_WRITEABLE,
58 }, {
59 .name = "firmware",
60 .offset = 0x020000,
61 .size = 0xfd0000,
62 }
63 };
8M::
0x000000000000-0x000000020000 : "u-boot"
0x000000020000-0x000000160000 : "kernel"
0x000000160000-0x0000007f0000 : "rootfs"
0x000000620000-0x0000007f0000 : "rootfs_data"
0x0000007f0000-0x000000800000 : "art"
0x000000020000-0x0000007f0000 : "firmware"
4M::
0x000000000000-0x000000020000 : "u-boot"
0x000000020000-0x000000160000 : "kernel"
0x000000160000-0x0000003f0000 : "rootfs"
0x000000304000-0x0000003f0000 : "rootfs_data"
0x0000003f0000-0x000000400000 : "art"
0x000000020000-0x0000003f0000 : "firmware"
16M::
0x000000000000-0x000000020000 : "u-boot"
0x000000020000-0x000000160000 : "kernel"
0x000000160000-0x000000ff0000 : "rootfs"
0x000000380000-0x000000ff0000 : "rootfs_data"
0x000000ff0000-0x000001000000 : "art"
0x000000020000-0x000000ff0000 : "firmware"
最後是編譯,其實編譯命令最簡單
#make
如果是多核CPU,可以增加參數,常規用法為 <您cpu處理器的數目 + 1> – 例如使用3進程來編譯 (即雙核CPU), 命令如下:
#make -j 3
如果想看到編譯過程中的錯誤信息,可以增加一個V=99或者V=s的參數。
生成鏡像(Image)位置
新生成的鏡像會默認放在新建的一個bin目錄下。例如:/bin/brcm-2.4/packages
[openwrt@localhost trunk]$ ls bin/*
將編譯好的鏡像做個備份,例如備份到/目錄下:
[openwrt@localhost trunk]$ cp bin /
清理工作
建議現在清理編譯產生的文件,以免下次編譯時造成沖突,(文件如果存在的話,將不會被替換),執行make clean
注意:在執行clean命令,確保已經將編譯好的image進行了備份。清理工作會清楚bin目錄。
[openwrt@localhost trunk]$ make clean
除了清除生成的目錄,還想清除交叉編譯工具(以及工具鏈目錄)
[openwrt@localhost trunk]$ make dirclean
清除所有相關的東西,包括下載的軟件包,配置文件,feed內容等:(不建議使用)
[openwrt@localhost trunk]$ make distclean
對於更新feeds後出現的錯誤:
ERROR:please fix package/feeds/packages/mc/Makefile 等類似的問題,需要執行這條語句進行系統的清理