sady 发表于 2011-10-7 10:21

tomato 编译详解

本帖最后由 sady 于 2011-10-7 19:11 编辑

看这个帖子这前, 请确认一下您能自己搞定ubuntu或debian的安装, 不管是vm下安装,或实体机安装均可以, 如果您不知道如何安装它们并使之正常运行, 请移步linux社区或论坛学习或放弃..本帖假设您已安装好ubuntu 并可以正常运行和上网.

一. 先打开 linux终端,在终端命令行下执行,安装编译所需的组件
sudo apt-get install build-essential linux-headers-$(uname -r)
sudo apt-get install libncurses5 libncurses5-dev m4 bison flex libstdc++6-4.4-dev g++-4.4 g++ libtool sqlite
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip zlib1g-dev
sudo apt-get install libc6 libncurses5-devautomake automake1.7 automake1.9
sudo apt-get install git-core
sudo apt-get install gitk
以上每复制一行,然后在终执行一次, 如果都可以顺利完成,请看下一步

二. 获取tomato源代码cd ~
sudo -s
mkdir tomato_git
cd tomato_git
git clone git://repo.or.cz/tomato.git稍等10~30分钟(取决于网速),完成后,先备份好源码以便在编译时改乱了,能恢复原始状态,需不要重复痛苦的重新下载源码tar zcvf tomato_git.tar.gz ./tomato完成后,将在当前目录下生成tomato_git.tar.gz 备份包, 以备不时之需.

如果源码有更新, 那么不需要重新下载源码,只需执行下列命令,可增量同步更新git pull三. 建立交叉编译变量环境sudo ln -s ~/tomato_git/tomato/tools/brcm /opt/brcmnano /root/.profile
在最后一行处加入
if [ -d "/opt/brcm" ] ; then
    PATH=/opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin:$PATH
fi
按ctrl+x y 保存退出, 以便每次启动linux时能找到编译器.四. 查看并获取当前tomato 分支源码

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

1.查看当前源码分支
cd ~/tomato_git/tomato
git branch -r
例:
debian:~/tomato_git/tomato# git branch -r
origin/Clientmon
origin/HEAD -> origin/tomato
origin/IPT-X
origin/QOS-DEV
origin/QOS-Limiter
origin/Static-ARP
origin/Teaman-BWM
origin/Teaman-IPTraffic
origin/Teaman-ND
origin/Teaman-ND-SDHC
origin/Teaman-RT
origin/Toastman-IPT-ND
origin/Toastman-ND
origin/Toastman-RT
origin/Toastman-RT-N
origin/Toastman-VLAN
origin/Toastman-VLAN-ND
origin/Toastman-VLAN-RT
origin/Toastman-VLAN-RT-N
origin/Tomato-RAF
origin/Transmission
origin/VLAN-GUI
origin/VLAN-MultiSSID
origin/minidlna
origin/multilanguage
origin/nfs_server
origin/ntfs-3g
origin/p910nd
origin/tomato
origin/tomato-K26-WL
origin/tomato-ND-USBmod
origin/tomato-ND-usbmod-mixvirtual**
origin/tomato-RT
origin/tomato-RT-N
origin/tomato-miniupnpd
origin/tomato-sdhc-ND-vlan
origin/tomato-shibby
origin/tomatovirtual**
origin/virtual**gui
origin/vsftpd
debian:~/tomato_git/tomato#
2. 获取分支源码

吐司超人版:git checkout origin/Toastman-RT
git checkout -b origin/Toastman-RT
Shibby mod版git checkout origin/tomato-shibby
git checkout -b origin/tomato-shibby但是要注意,您一次只能获取一种分支源码,不能同时下载, 如果已经下载了吐司超人版源码.. 后来又想编译Shibby源码,那么需要将整个tomato目录删掉,重新解压源码备份,再获取shibby源码,这样获得的源码才干净.sudo rm -rf ~/tomato_git/tomato
tar zxvf ~/tomato_git/tomato.tar.gz .四. 开始编译.
如果需要自己配置核心, 添加对更多硬件的支持. 那么R1版:
cd ~/tomato_git/tomato/release/src/linux/linux
或R2版:
cd ~/tomato_git/tomato/release/src-rt/linux-2.6

sudo make menuconfig

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

开始编译.R1版:
cd ~/tomato_git/tomato/release/src
或R2版:
cd ~/tomato_git/tomato/release/src-rt
查看有那些参数可选.不同的分支版本,编译参数是不同的.具体查看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-virtual** - (BT plus virtual**)
a            Big - (Ext plus NOCAT plus NFS plus BT gui)
n            Mega - (Big + BT Client minus NOCAT)
e            virtual** - (standard plus virtual**, extra utilities and NTFS support)
b            Big-virtual** - (Big plus virtual**)
o            Mega-virtual** - (Mega plus virtual** 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            virtual** (no usb) - (virtual** with no USB support)
w            SD-virtual** (no usb) - (virtual** 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-virtual**
r2a          MIPS Release 2 Big
r2n          MIPS Release 2 Mega
r2e          MIPS Release 2 virtual**
r2b          MIPS Release 2 Big-virtual**
r2o          MIPS Release 2 Mega-virtual**
r2z          MIPS Release 2 AIO (for routers +8MB flash)
r2v          MIPS Release 2 virtual** (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-virtual**
n60a         Linksys E-series build Big
n60n         Linksys E-series build Mega
n60e         Linksys E-series build virtual**
n60b         Linksys E-series build Big-virtual**
n60o         Linksys E-series build Mega-virtual**
n60s         Linksys E-series build Std with IPv6
n60v         Linksys E-series build virtual** with IPv6


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

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

五. 重新编译同一版本
make clean

改动较大版本
make distclean

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

六. 其他
如果您决定编译shibby源码最新版. 因为最新版的transmission需要libevent-2.0.10 以上组件, 请替换掉源码中的libevent旧版本,再进行编译.否则会出错rm -rf ~/tomato_git/tomato/release/src/router/libevent/
wget http://www.monkey.org/~provos/libevent-2.0.10-stable.tar.gz

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-build-and-rebuild-tomato-for-total-noobs

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

补充内容 (2012-1-31 23:49):
TT核心配置方面,make menuconfig 后会生成.config 文件,此配置文件在编译TT过程中会被删除,需要处理一下:
mv config_base config_base_bak
cp .config config_base


补充内容 (2012-1-31 23:50):
还有就是默认情况下编译shibby 下transmission会到libevent时会出错,处理方法是在 src/router/libevent 下运行一下./Configure 生成配置文件,再回头继续编译,不用替换源码了。

fugcon 发表于 2011-10-7 16:06

10-30分钟能下载完源码,想必楼主的网速很不错

小标 发表于 2011-10-7 17:52

:lol终于看到tomato的编译教程了,感谢楼主。

myeyre 发表于 2011-10-7 18:48

收到

感觉开头装的组件稍有点乱

sady 发表于 2011-10-7 18:58

2# fugcon


我的网速是10M, 当时下载没有注意时间. 这是个估算值

打包后的源码大小为728M ..

顺便给大家提供一些有用的资料. 给喜欢研究的路友.

http://digiland.tw/viewtopic.php?id=372

小标 发表于 2011-10-7 23:43

谢谢楼主的教程,今晚下载完源码了,编译前有几点疑问:编译Tomato可不可以像编译Openwrt那样,只选择编译某型号路由用的固件呢,例如想编译适合中兴h618b用的;tomato的分支较多,那一个分支是中文界面的?希望楼主能解答一下。

sady 发表于 2011-10-8 09:15

本帖最后由 sady 于 2011-10-8 09:19 编辑

不可以,tomato编译没有指定路由型号的选项, 如果针对特定的路由编译个性化的固件,先要了解此路由的硬件如cpu型号,网卡型号等,然后改核心配置文件与之相对应,再编译.

目前只有Shibby分支提供多语言切换功能,包含中文, 此功能为Shibby特有,内置一个类似于sed s/英文/中文/g 类的脚本替换程序.
不过普通的版本也可以汉化,将src/router/www下文件下载到电脑上, 然后手动翻译,再拷回去重新编译,就是中文界面了, 这不是技术活, 纯体力活,因为文件很多考验你的耐力. 也可以用现成的其他中文版中文页面文件,把它们拷出来,再对比替换. 这样可以大大降低工作量.

小标 发表于 2011-10-8 12:00

编译出错了,是按照教程的步骤一步一步来做的,下面是出错的截图,麻烦楼主看看问题出在那。

sady 发表于 2011-10-8 13:34

编译出错是再正常不过的事情, 不出错才是比较少见的

你的问题好像是出在找不到编译器. 可能是未指明路径.

试试先执行.

sudo ln -s ~/tomato_git/tomato/tools/brcm /opt/brcm
PATH=/opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin:$PATH

然后再重新make.

小标 发表于 2011-10-9 08:10

还是同样的错,先后用Ubuntu11.4和ylmf3.0来编译,都出现同样的问题,估计是在设置交叉编译变量环境这个步骤没设置对,等等上传个截图麻烦楼主帮忙看看。

徐游 发表于 2011-10-9 21:56

强人,好帖,一定要支持

flame 发表于 2011-10-10 14:27

帮顶了!!!!!!!!!!!!!!!!!!!

春暖花开 发表于 2011-10-10 19:55

版主还不快射精,真hold住了

小标 发表于 2011-10-11 19:56

:lol感谢楼主,看了楼主的教程也看了数位天堂上的编译教程,折腾编译N次,终于编译出来了。

q741451 发表于 2011-10-12 02:07

环境变量和交叉编译链就已经难倒一大批人了,何况很多源码本身存在问题
页: [1] 2 3 4 5
查看完整版本: tomato 编译详解