分类: 电脑技术
作者: admin

tomato 编译详解

一. 先打开 linux终端,在终端命令行下执行,安装编译所需的组件

  1. sudo apt-get install build-essential linux-headers-$(uname -r)
  2. sudo apt-get install libncurses5 libncurses5-dev m4 bison flex libstdc++6-4.4-dev g++-4.4 g++ libtool sqlite
  3. sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip zlib1g-dev
  4. sudo apt-get install libc6 libncurses5-dev  automake automake1.7 automake1.9
  5. sudo apt-get install git-core
  6. sudo apt-get install gitk
复制代码

以上每复制一行,然后在终执行一次, 如果都可以顺利完成,请看下一步

二. 获取tomato源代码

  1. cd ~
  2. sudo -s
  3. mkdir tomato_git
  4. cd tomato_git
  5. git clone git://repo.or.cz/tomato.git
复制代码

稍等10~30分钟(取决于网速),完成后,先备份好源码以便在编译时改乱了,能恢复原始状态,需不要重复痛苦的重新下载源码

  1. tar zcvf tomato_git.tar.gz ./tomato  
复制代码

完成后,将在当前目录下生成tomato_git.tar.gz 备份包, 以备不时之需.

如果源码有更新, 那么不需要重新下载源码,只需执行下列命令,可增量同步更新

  1. git pull
复制代码

三. 建立交叉编译变量环境

  1. sudo ln -s ~/tomato_git/tomato/tools/brcm /opt/brcm
复制代码
  1. nano /root/.profile
  2. 在最后一行处加入
  3. if [ -d "/opt/brcm" ] ; then
  4.     PATH=/opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin:$PATH
  5. fi
  6. 按ctrl+x y 保存退出, 以便每次启动linux时能找到编译器.
复制代码

四. 查看并获取当前tomato 分支源码

这部分源码并不包含在前面的源码包中, 需要另外下载,

1.查看当前源码分支

  1. cd ~/tomato_git/tomato
  2. git branch -r
  3. 例:
  4. debian:~/tomato_git/tomato# git branch -r
  5.   origin/Clientmon
  6.   origin/HEAD -> origin/tomato
  7.   origin/IPT-X
  8.   origin/QOS-DEV
  9.   origin/QOS-Limiter
  10.   origin/Static-ARP
  11.   origin/Teaman-BWM
  12.   origin/Teaman-IPTraffic
  13.   origin/Teaman-ND
  14.   origin/Teaman-ND-SDHC
  15.   origin/Teaman-RT
  16.   origin/Toastman-IPT-ND
  17.   origin/Toastman-ND
  18.   origin/Toastman-RT
  19.   origin/Toastman-RT-N
  20.   origin/Toastman-VLAN
  21.   origin/Toastman-VLAN-ND
  22.   origin/Toastman-VLAN-RT
  23.   origin/Toastman-VLAN-RT-N
  24.   origin/Tomato-RAF
  25.   origin/Transmission
  26.   origin/VLAN-GUI
  27.   origin/VLAN-MultiSSID
  28.   origin/minidlna
  29.   origin/multilanguage
  30.   origin/nfs_server
  31.   origin/ntfs-3g
  32.   origin/p910nd
  33.   origin/tomato
  34.   origin/tomato-K26-WL
  35.   origin/tomato-ND-USBmod
  36.   origin/tomato-ND-usbmod-mixvpn
  37.   origin/tomato-RT
  38.   origin/tomato-RT-N
  39.   origin/tomato-miniupnpd
  40.   origin/tomato-sdhc-ND-vlan
  41.   origin/tomato-shibby
  42.   origin/tomatovpn
  43.   origin/vpngui
  44.   origin/vsftpd
  45. debian:~/tomato_git/tomato#
复制代码

2. 获取分支源码

吐司超人版:

  1. git checkout origin/Toastman-RT
  2. git checkout -b origin/Toastman-RT
复制代码

Shibby mod版

  1. git checkout origin/tomato-shibby
  2. git checkout -b origin/tomato-shibby
复制代码

但是要注意,您一次只能获取一种分支源码,不能同时下载, 如果已经下载了吐司超人版源码.. 后来又想编译Shibby源码,那么需要将整个tomato目录删掉,重新解压源码备份,再获取shibby源码,这样获得的源码才干净.

  1. sudo rm -rf ~/tomato_git/tomato
  2. tar zxvf ~/tomato_git/tomato.tar.gz .
复制代码

四. 开始编译.
如果需要自己配置核心, 添加对更多硬件的支持. 那么

  1. R1版:
  2. cd ~/tomato_git/tomato/release/src/linux/linux
  3. 或R2版:
  4. cd ~/tomato_git/tomato/release/src-rt/linux-2.6
  5.  
  6. sudo make menuconfig
复制代码

根据情况自行选择内核参数, 没有经验不建议更改,很容易导致核心挂掉(省略5000字)

开始编译.

  1. R1版:
  2. cd ~/tomato_git/tomato/release/src
  3. 或R2版:
  4. cd ~/tomato_git/tomato/release/src-rt
复制代码

查看有那些参数可选.不同的分支版本,编译参数是不同的.具体查看

  1. make help
复制代码

例:
debian:~/tomato_git/tomato/release/src-rt# make help
m            Ext - (standard plus extra utilities and NTFS support)
c            BTgui - (Ext plus BT gui)
r            BT - (Ext plus BT Client)
t            BT-VPN - (BT plus VPN)
a            Big - (Ext plus NOCAT plus NFS plus BT gui)
n            Mega - (Big + BT Client minus NOCAT)
e            VPN - (standard plus VPN, extra utilities and NTFS support)
b            Big-VPN - (Big plus VPN)
o            Mega-VPN - (Mega plus VPN plus NOCAT minus NFS)
i            MiniIPv6 - (IPv6 with no USB support minus CIFS and RIPv1/2)
s            Std - (no USB support)
f            Mini - (no USB support minus CIFS and RIPv1/2)
v            VPN (no usb) - (VPN with no USB support)
w            SD-VPN (no usb) - (VPN with SD-MOD and no USB support)
r2m          MIPS Release 2 Ext
r2c          MIPS Release 2 BTgui
r2r          MIPS Release 2 BT
r2t          MIPS Release 2 BT-VPN
r2a          MIPS Release 2 Big
r2n          MIPS Release 2 Mega
r2e          MIPS Release 2 VPN
r2b          MIPS Release 2 Big-VPN
r2o          MIPS Release 2 Mega-VPN
r2z          MIPS Release 2 AIO (for routers +8MB flash)
r2v          MIPS Release 2 VPN (no usb)
r2s          MIPS Release 2 Std
r2i          MIPS Release 2 MiniIPv6 (for 4MB flash)
r2f          MIPS Release 2 Mini (for netgear)
n60m         Linksys E-series build Ext
n60c         Linksys E-series build BTGui
n60r         Linksys E-series build BT
n60t         Linksys E-series build BT-VPN
n60a         Linksys E-series build Big
n60n         Linksys E-series build Mega
n60e         Linksys E-series build VPN
n60b         Linksys E-series build Big-VPN
n60o         Linksys E-series build Mega-VPN
n60s         Linksys E-series build Std with IPv6
n60v         Linksys E-series build VPN with IPv6


开始编译

  1. sudo make V1=Shibby V2=-20111007 r2r
复制代码

说明: 其中V1=分支名称 ,V2=版本号, 两个可以自定义,也可以都不要,您自己决定. 它会出现在固件的about 页面中的版本中. r2r是表示编译的是r2版本带内置bt的功能.

可以休息了, 大约1小时到2小时,取决您的电脑速度.
中间如果有出错,请根据出错提示信息纠错解决(需要一定经验和知识)
编译完成. 在当前的image目录下可查到,将它复制出来.然后刷机,测试..

五. 重新编译

  1. 同一版本
  2. make clean
  3.  
  4. 改动较大版本
  5. make distclean
复制代码

清整掉以后,再用本节方法重新make.

六. 其他
如果您决定编译shibby源码最新版. 因为最新版的transmission需要libevent-2.0.10 以上组件, 请替换掉源码中的libevent旧版本,再进行编译.否则会出错

  1. rm -rf ~/tomato_git/tomato/release/src/router/libevent/
  2. wget http://www.monkey.org/~provos/libevent-2.0.10-stable.tar.gz
  3.  
  4. tar xzvf libevent-2.0.10-stable.tar.gz -C ~/tomato_git/tomato/release/src/router/libevent/
复制代码

补充参考网站:
tomatousb官网编译教程(此教程没有说明如何获取tomato分支代码)
http://tomatousb.org/tut:how-to- ... ato-for-total-noobs

数位天堂tomato讨论区,认真看,受益非浅.
http://digiland.tw/viewforum.php?id=42