How to compile Tomato Firmware

How to rebuild Tomato (quickie half-baked instructions)

Quickie partial guideline. Not guaranteed to be complete or entirely correct.

Install necessary software

(This is one-time only setup.)
You can use either a dedicated machine or a virtual machine on your Windows desktop computer. The instructions below are for an Ubuntu system, but you can use almost any Linux distribution (the exact package names may vary between distributions).

Install these packages (I used synaptic: "sudo synaptic")

  • libncurses5
  • libncurses5-dev
  • m4
  • bison
  • gawk
  • flex
  • libstdc++6-4.4-dev
  • g++-4.4
  • g++
  • git
  • gitk
  • zlib1g-dev

Download source

In the instructions below we use "$HOME/tomato" as the top directory where your Tomato source tree will be located. Replace it with whatever you want, if you prefer to have it in another place.

You can either clone the Tomato git repository locally (preferred way), or just download the complete Tomato source in the tarball.

Method 1: clone the git repository

When using this method, you only will need to download the complete sources once. Later, when updating your local git clone, you will only download updates to the previous state of your repository.

Navigate to the directory where you're going to create your Tomato source tree (do not create the "tomato" directory yet), and clone the repository locally ("tomato" in the command below is the new directory name for cloned repository - it will be created by git):

cd $HOME
git clone git:// tomato

Prepare to wait for a while - when you're cloning the repo for the first time it will download a lot of data. For future updates, use:
git fetch

Now you should be able to checkout the current version of any of the existing branches:
cd $HOME/tomato
git checkout origin/tomato-ND-USBmod
# OR
git checkout origin/tomato-RT

To checkout the state of the code corresponding to a specific released version, use the tag name instead of the branch name, i.e.:
git checkout tomatousb-K26-1.28.9052.beta23
# OR
git checkout tomatousb-ND-1.28.8752

To view all branches, tags and commits in a graphical UI:
gitk --all &

For additional git and gitk commands, refer to this Crash Course.

Method 2: download as a tarball

This method might be easier to use if you're not familiar with git, but you will have to download the complete tarball with all sources every time you'd like to get an updated code.

Navigate to Tomato source tree top directory:

cd $HOME/tomato

Go to Downloads page scroll to the bottom under "Source Code". Click on the link to download the snapshot of the branch you want to build (K24 or K26). This goes through git, so prepare to wait… git is VERY slow. I sometimes have trouble here, so I go to the git repository link and download from there. Also, when it pops up and asks you where to DL the file, I always manually stick in the version number (like '-v52-'). Untar it:
tar xf tomato-v52-the_long_and_cryptic_name_of_the_file_you_just_downloaded.tar.gz

Detailed instructions vary here. Personally, I download onto my Windows box and then manually copy the file to my Linux box. Also, I untar to a "tomato-src" directory, and rename the tomato directory to the version number. Ex: 'mv tomato v52'. Then I copy it to my main tomato directory, ex:

cp /aT ~/tomato-srcs/v52/ ~/tomato/

Setup your development system

Set up the symlink (you might need to do this as root):

ln -s $HOME/tomato/tools/brcm /opt/brcm

Put this line into your shell .profile file:

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

or just execute it manually.


When building K26 build from tomato-RT branch:

cd $HOME/tomato/release/src-rt

When building K24 build from tomato-ND-USBmod branch:
cd $HOME/tomato/release/src

Then execute "make":
make <target(s)> V1=v52 V2=_tailored_name

  • <target(s)> - one or multiple make targets indicating the build type. Run 'make help' for the list of supported targets with descriptions.
  • V1 is the major name. I always use the released version number.
  • V2 is the name of your tailored code. Example: V2=_no_tcp_vegas.

After awhile (3 to 20 minutes or so, depends on your hardware and how much must be recompiled), you'll get a message like this:

Creating TRX: image/tomato-NDUSB-1.28.v52_novegas-Std.trx

TRX Image:
 Total Size .... : 3416064 (3336.0 KB) (3.3 MB)
   Images ...... : 3413988 (0x003417e4)
   Padding ..... : 2048
 Avail. for jffs :
   4MB, 128K CFE : 8 EBs + 57344
   4MB, 256K CFE : 6 EBs + 57344
   8MB, 256K CFE : 70 EBs + 57344
            Note : Netgear routers  have 6 EBs less available!
 CRC-32 ........ : D3581692
 128K Blocks ... : 27 (0x0000001B)
  64K Blocks ... : 53 (0x00000035)
   0: 0x0000001C  lzma-loader/loader.gz
   1: 0x00000A8C  /home/ray/tomato-v52/release/src/linux/linux/arch/mips/brcm-boards/bcm947xx/com
   2: 0x0007EC00  router/mipsel-uclibc/target.image

you'll get an error message, either from the compiler or from make complaining that some needed program isn't there. Like "sh: command not found: bison". That means you need to install the missing package.

Then go to the router GUI and admin/upgrade, using the TRX file you just built.

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