How to build, and rebuild Tomato, FOR TOTAL NOOBS



How to build, and rebuild Tomato, FOR TOTAL NOOBS:

¡ADVICE!
This tutorial is a bit outdated, I'll update it when I have some time left, anyway it should still be usefull, but before compiling read the latest makefile.

The first step is to get yourself a linux environment.
I suggest using a noob friendly build like Ubuntu.
You can use it as live distro, install it, or create a virtual machine.
As this is a totalnoob guide, I am inclined to think all of you reading this come from windows, so the easiest way is to create a Virtual machine and then installing Ubuntu on it.
For this guide to work correctly, or just to work, you need internet connection, except for the How to compile the latest tomato snapshots, if you have allready downloaded the snapshot.

Menu:
Creating a linux environment using a Virtual Machine
How to compile Official tomato releases from git
How to compile latest tomato snapshots from git
How to compile the latest tomato snapshots
Commands
Videotutorial
Troubleshooting
Feedback:
Compiled builds
.
.
.

Creating a linux environment using a Virtual Machine: (Return to top)

1º. Install a virtual machine, I suggest Oracle VM Virtualbox, which is free and has all you need. (http://www.virtualbox.org/wiki/Downloads)
2º. Create a new virtual machine following the instructions.
3º. Download your linux iso and mount it on a dvd drive (virtual or not).
4º. Now on the main window of Virtualbox (if you are using this virtual environment), right click on your newly created virtual machine and go into configuration, adjust the settings as you like, and go into storage select ide and where you read cd/dvd empty select the drive where you have your linux distro mounted.
5º. Accept the changes and run your virtual machine.
6º. Now install your distro, in my case I suggest using the latest Ubuntu build, (http://www.ubuntu.com/desktop/get-ubuntu/download).
7º. Now that you have your linux environment installed, you must, or should install “guest additions”. This will allow you to resize the window of the virual machine, copy text from windows to your virtual machine, and a much more pleasant experience. To do this easily just open terminal, (if you are in Ubuntu, go to applications, accessories and click on terminal), and type:

sudo apt-get install build-essential linux-headers-$(uname -r)

It will ask your user password, as sudo command needs it to give you administrative privilidges.

sudo apt-get install virtualbox-ose-guest-x11
sudo reboot

This will reboot.
If you want, Ubuntu will prompt you with updates, there will be no harm if you update or if you don’t, I personally always update everything :p.
Now you’ll see everything is much more fluid and friendly to use.
Now that you have your linux environment up and running, lets start playing:
.
.
.

How to compile Official tomato releases from git: (Return to top)
(I recommend not to close terminal on the whole process).

First you must install all dependencies and build tools necessary, for this you have two ways:

1º. Go into synaptic and do it manually, I suggest this method for this packaged (it is located in Ubuntu under system, administration, synaptics package manager).

libncurses5, libncurses5-dev, m4, bison, flex, libstdc++6-4.4-dev, g++-4.4, g++, libtool, sqlite

or

2º. Go into terminal and type:

sudo apt-get install libncurses5 libncurses5-dev m4 bison flex libstdc++6-4.4-dev g++-4.4 g++ libtool sqlite

Now again on terminall type:

sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip zlib1g-dev
sudo apt-get install libc6 libncurses5-dev  automake automake1.7 automake1.9
sudo apt-get install git-core

For X64 systems also:

sudo apt-get install libc6-i386 lib32z-dev

and (optional)

sudo apt-get install gitk

3º. Create a directory and go into it (cd)

mkdir tomato_git
cd tomato_git

4º. Clone the tomato repository onto your new folder, this will take a while so go take a coffee.

git clone git://repo.or.cz/tomato.git

(Once downloaded the git, to update it just type cd ~/tomato_git/tomato and git pull if that dosnt work, delet the tomato_git folder, and start the process from 3º point on)

5º. Now you must select the version of tomato which you want to work with, if you want to compile Tomatousb, search for the latest version and copy its whole name, to do this type:

cd tomato

or
cd ~/tomato_git/tomato

if you closed terminal.
When in tomato_git/tomato type:
git tag | grep tomato*

This will show all the names of the different tomato build available, copy the one you want to build, in our case the latest tomatousb (in this moment its tomatousb-K26-1.28.9052.beta23 or the k24 version)
or:
gitk --all &

which will show you all branches, tags and commits in a graphical UI.
Once selected, type:
git checkout theversionyouselected

example:
git checkout tomatousb-K26-1.28.9052.beta23

6º. Now you must create another folder to work, for example called tomato.
mkdir ~/tomato

7º. Copy what is inside “~/tomato_git/tomato” into “~/tomato” just copy it manually, but leave the tomato folder inside tomato_git.
If you don’t know were to look, the tomato and the tomato_git folders should be on:
places, computer, file system, home, and whatever your username is.
8º. When the transfer has finished, you must create a symlink, so on terminal type:
sudo ln -s ~/tomato/tools/brcm /opt/brcm

9º. Execute this manually by typing it on terminal or put this line into your shell .profile file:

export PATH=$PATH:/opt/brcm/hndtools-mipsel-linux/bin:/opt/brcm/hndtools-mipsel-uclibc/bin

Optional:
If you dont want to execut this each time you reboot:
Add the following to the end of your user .profile file:

if [ -d "/opt/brcm" ] ; then
    PATH=/opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin:$PATH
fi

10º. Go into your source folder:

cd ~/tomato/release/src-rt
(for k26 builds)

or

cd ~/tomato/release/src
(for k24 build)

11º. Clean the work (not necesary, but recomended if you have compiled another build before)

make clean

12º. And last but not least, lets compile ^^.

make V1=version example 9052 V2=tailored name example beta23 command

some examples would be:

make V1=9052 V2=beta23 e3000
make V1=9052 V2=beta23 e2000
make V1=9052 V2=beta23 r2m
etc

The compiled firmware will be under tomato/release/src-rt/image for k26 builds and tomato/release/src/image for k24.

On command you can specify specific builds, for example e3000 will build tomatousb extras with 60k nvram, e2000 will build standart no usb with 60k nvram, for more commands type make help on the specific directory you want (k24 will be src, k26 will be src-rt), here you have the list of availible commands:
Commands

13º. So this is all, type on terminal to clean a bit:

make  clean

14º. YAY if you were lucky and followed all correctly you will have a new folder (image) on tomato/realease/src-rt or tomato/realease/src, which will have your newly built firmware.
.
.
.

How to compile latest tomato snapshots from git: (Return to top)

(I recommend not to close terminal on the whole process).

First you must install all dependencies and build tools necessary, for this you have two ways:
1º. Go into terminal and type:

sudo apt-get install libncurses5 libncurses5-dev m4 bison flex libstdc++6-4.4-dev g++-4.4 g++ libtool sqlite

or go into synaptic and do it manually (it is located in Ubuntu under system, administration, synaptics package manager).
2º. Now again on terminall type:

sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip zlib1g-dev
sudo apt-get install libc6 libncurses5-dev  automake automake1.7 automake1.9
sudo apt-get install git-core

and (optional)
sudo apt-get install gitk

3º. Create a directory and go into it (cd)

mkdir tomato_git
cd tomato_git

4º. Clone the tomato repository onto your new folder, this will take a while so go take a coffee.

git clone git://repo.or.cz/tomato.git

(Once downloaded the git, to update it just type cd ~/tomato_git/tomato and git pull if that dosnt work, delet the tomato_git folder, and start the process from 3º point on)

5º. Now you must select the version of tomato which you want to work with, if you want to compile Tomatousb, search for the latest version and copy its whole name, to do this type:

cd tomato

or
cd ~/tomato_git/tomato

if you closed terminal.
When in tomato_git/tomato type:
For k24
git checkout origin/tomato-ND-USBmod

or for k26
git checkout origin/tomato-RT

6º. Now you must create another folder to work, for example called tomato.
mkdir ~/tomato

7º. Copy what is inside “~/tomato_git/tomato” into “~/tomato” just copy it manually, but leave the tomato folder inside tomato_git.
If you don’t know were to look, the tomato and the tomato_git folders should be on:
places, computer, file system, home, and whatever your username is.
8º. When the transfer has finished, you must create a symlink, so on terminal type:
sudo ln -s ~/tomato/tools/brcm /opt/brcm

9º. Execute this manually by typing it on terminal or put this line into your shell .profile file:

export PATH=$PATH:/opt/brcm/hndtools-mipsel-linux/bin:/opt/brcm/hndtools-mipsel-uclibc/bin

Optional:
If you dont want to execut this each time you reboot:
Add the following to the end of your user .profile file:
if [ -d "/opt/brcm" ] ; then
    PATH=/opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin:$PATH
fi

10º. Go into your source folder:

cd ~/tomato/release/src-rt
(for k26 builds)

or

cd ~/tomato/release/src
(for k24 build)

11º. Clean the work (not necesary, but recomended if you have compiled another build before)

make clean

12º. And last but not least, lets compile ^^.

make V1=version example 9052 V2=tailored name example beta23 command

some examples would be:

make V1=9052 V2=beta23 e3000
make V1=9052 V2=beta23 e2000
make V1=9052 V2=beta23 r2m
etc

The compiled firmware will be under tomato/release/src-rt/image for k26 builds and tomato/release/src/image for k24.

On command you can specify specific builds, for example e3000 will build tomatousb extras with 60k nvram, e2000 will build standart no usb with 60k nvram, for more commands type make help on the specific directory you want (k24 will be src, k26 will be src-rt).
The full commands are listed above under step 12 of the official git tuto.here you have the list of availible commands:
Commands

13º. So this is all, type on terminal to clean a bit:

make  clean

14º. YAY if you were lucky and followed all correctly you will have a new folder (image) on tomato/realease/src-rt or tomato/realease/src, which will have your newly built firmware.
.
.
.

How to compile the latest tomato snapshots: (Return to top)
(I recommend not to close terminal on the whole process).

First you must install all dependencies and build tools necessary, for this you have two ways:
1º. Go into terminal and type:

sudo apt-get install libncurses5 libncurses5-dev m4 bison flex libstdc++6-4.4-dev g++-4.4 g++ libtool sqlite

or go into synaptic and do it manually (it is located in Ubuntu under system, administration, synaptics package manager).
2º. Now again on terminall type:

sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip zlib1g-dev
sudo apt-get install libc6 libncurses5-dev  automake automake1.7 automake1.9

3º Go to http://tomatousb.org/download and download the latest snapshot.
There you will find the file under Downloads. Now you must untar it, type on terminal:

tar xvf Name of the file.tar.gz

Now wait until terminal has gone to normal, finished working.
example:
tar xvf tomato-tomato-RT.tar.gz

4º. Once untared right click on the tomato folder created on downloads and select copy to home folder.
5º. When the transfer has finished, you must create a symlink, so on terminal type:
sudo ln -s ~/tomato/tools/brcm /opt/brcm

6º. Execute this manually by typing it on terminal or put this line into your shell .profile file:

export PATH=$PATH:/opt/brcm/hndtools-mipsel-linux/bin:/opt/brcm/hndtools-mipsel-uclibc/bin

Optional:
If you dont want to execut this each time you reboot:
Add the following to the end of your user .profile file:
if [ -d "/opt/brcm" ] ; then
    PATH=/opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin:$PATH
fi

7º. Go into your source folder:

cd ~/tomato/release/src-rt
(for k26 builds)

or

cd ~/tomato/release/src
(for k24 build)

8º. And last but not least, lets compile ^^.

make V1=version example 9052 V2=tailored name example beta23 command

some examples would be:

make V1=9052 V2=beta23 e3000
make V1=9052 V2=beta23 e2000
make V1=9052 V2=beta23 r2m
etc

The compiled firmware will be under tomato/release/src-rt/image for k26 builds and tomato/release/src/image for k24.

On command you can specify specific builds, for example e3000 will build tomatousb extras with 60k nvram, e2000 will build standart no usb with 60k nvram, for more commands type make help on the specific directory you want (k24 will be src, k26 will be src-rt)
here you have the list of availible commands:
Commands

9º. So this is all, type on terminal to clean a bit:
make clean

10º. YAY if you were lucky and followed all correctly you will have a new folder (image) on tomato/realease/src-rt or src/image, which will have your newly built firmware.

Flash from windows:

If you preffer to flash your router from windows, send it to your email XD and download it in windows, or use the shared folder on your virtual machine, etc.
Flash it from stock(recomended) or ddwrt, do a nvram reset, and have fun with your new Tomato router.
.
.
.

Commands: (Return to top)
k26 commands:
a A build (standard)
b B build (standard minus SSH)
c C build (standard minus CIFS)
d D build (standard minus Samba server)
m M build (standard plus extra utilities and NTFS support)
e E build (standard plus VPN, extra utilities and NTFS support)
s S build (no USB support)
f F build (no USB support minus JFFS and CIFS)
v V build (VPN with no USB support)
e3000 Linksys E3000 build (standard plus extras)
e3000v Linksys E3000 build (standard plus VPN)
e2000 Linksys E2000 build (no USB support)
r2m MIPS Release 2 M build (standard plus extras)
r2e MIPS Release 2 E build (standard plus VPN and extras)
r2v MIPS Release 2 V build (VPN with no USB support)
r2s MIPS Release 2 S build (no USB support)
r2f MIPS Release 2 F build (no USB support minus JFFS and CIFS)
..etc.. other build configs
clean -C router clean
cleanimage rm -rf image
cleantools clean btools, mksquashfs
cleankernel -C Linux distclean (but preserves .config)
distclean distclean of Linux & busybox (but preserve .configs)
prepk -C Linux oldconfig dep
libc -C uClibc clean, all, install

k24 commands:
a A build (standard)
b B build (standard minus SSH)
c C build (standard minus CIFS)
d D build (standard minus Samba server)
m M build (standard plus extra utilities and NTFS support)
e E build (standard plus VPN, extra utilities and NTFS support)
s S build (no USB support)
f F build (no USB support minus JFFS and CIFS)
v V build (VPN with no USB support)
r2m MIPS Release 2 M build (standard plus extras)
r2e MIPS Release 2 E build (standard plus VPN and extras)
r2v MIPS Release 2 V build (VPN with no USB support)
r2s MIPS Release 2 S build (no USB support)
r2f MIPS Release 2 F build (no USB support minus JFFS and CIFS)
..etc.. other build configs
clean -C router clean
cleanimage rm -rf image
cleantools clean btools, mksquashfs
cleankernel -C Linux distclean (but preserves .config)
distclean distclean of Linux & busybox (but preserve .configs)
prepk -C Linux oldconfig dep
libc -C uClibc clean, all, install.
.
.
.
Videotutorial: (Return to top)
If after all, you still have problems with your setup, here is a videotutorial I made so that steps can be followed with visual input.
http://www.megaupload.com/?d=81K2AB3I
.
.
.

Troubleshooting: (Return to top)
There are sometimes, when rebuilding from git, or just rebuilding, that compiling fails, and gives multiple errors, and nothing seems to solve this.
This is because some configs have changed (unknown reason).
There are some ways to make the files usable again:

1. As you have copied the files inside the git folder, and didnt cut them,(in theory) you can delete your work folder ~/tomato, and copy again ~/tomato_git/tomato, and so you are off with a fresh copy to work with.

2. cd into your git folder:

cd ~/tomato_git/tomato

and type
git checkout .
git reset --hard

Then do a new checkout.

3. If that dosnt work, as teddy_bear suggested try:
cd into your git folder:

cd ~/tomato_git/tomato

and type
git clean -fdxq && git reset --hard

Then do a new checkout.

4. If that still dosnt work delete your git folder and do a new one clonin git and starting the process again.
.
.
.

Feedback: (Return to top)
I'm leaving this page on tutorial club fore feedback and suggestions:
http://tomatousb.org/forum/t-284204/how-to-build-and-rebuild-tomato-for-total-noobs
.
.
.

Hoped this helped someone.
All the credits of this guide goes for the ones who did http://www.linksysinfo.org/forums/showthread.php?t=64460 and
http://tomatousb.org/tut:how-to-rebuild-tomato-software
from which im making this guide, and to ddggttff3 who found http://repo.or.cz/w/tomato.git/blobdiff/a54d08e3821486dfe2cbaa712362ea712cc63694..d832816002f46a6de91f44aff961b0282ff72208:/release/src/Makefile, and of course to the developers of tomato and tomatousb, which make posible to make our routers something more, and specially to teddy_b.
.
.
.

Compiled builds (Return to top)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License