Building FreshTomato

Discussion in 'Tomato Firmware' started by Cold Winter, Aug 30, 2018.

  1. Cold Winter

    Cold Winter Networkin' Nut Member

    At the risk of seeming dense, I'm looking at the git repo
    and wondering where the top level makefile is situated.

    I'm studying the process to see if this can be built under
    an Arch Linux system... just for the challenge.

    Is there a more detailed build process doc somewhere?
  2. koitsu

    koitsu Network Guru Member

    1. Are the literal step-by-step-with-commands instructions in not sufficient? They're literally the best walk-through I've seen outside of what I wrote years ago for building Toastman (I've since taken down my blog so that info is gone). You have to read them slowly and carefully, but they're crystal clear:


    Or is all of that working for you and you're trying to figure out "where" to run make from? If so, what you need to know is this (for ARM. For MIPS, you want directory release/src-rt IIRC):

    cd release/src-rt-6.x.4708
    make {buildtype}

    {buildtype} is the type of firmware you want. Try make help else review the Makefile to get a list.

    Your firmware(s) will end up in the image/ directory.

    There are arguments V1 and V2 you can give make (ex. make V1=foo V2=bar {buildtype}) that will get auto-populated into the firmware itself as well as the filename. You'll need to experiment with these, as I believe they're different in FreshTomato (or Shibby?) than in Toastman.

    Your PATH being correct is probably the most important thing. Do not try to move directories around (ex. the /opt situation, symlinks, etc.); you must comply with the pathname convention. A lot of this is Broadcom's fault, not Tomato.

    You're also going to need to know that you quite often will need to "start over from scratch" when building the firmware if something goes awry. This doesn't mean reinstalling the OS, this means making sure the entire git directory structure is clean/pristine -- all object files/etc. are stored within the repo itself. make clean or make distclean will not clean things up or come even close. This is just how Tomato is. How to clean things out properly (verify with git status after!) to make sure your next make attempt is from the ground up:

    git reset --hard && git clean -dxf

    2. You are going to run into major packaging complications using ArchLinux, I can promise you that. They don't provide the exact same versions of necessary toolchain and build software (particularly GNU autotools) as others. I've discussed in the past in detail major issues with trying to use distros other than what the maintainers use (Debian 9.x 64-bit). The reason I was using Mint, BTW, was because that's what Toastman firmware is built with.

    As such, you should use the exact OS/distro, version, and architecture -- all 3 are VERY important! -- mentioned in to guarantee success. This isn't so much the fault of Tomato as it is the fault of the distros, packages, and GNU autotools.

    If you don't want to reinstall your OS then use a VM (ex. VirtualBox, VMware Workstation), or consider paying a small amount of money per month for a service like Linode to get such a machine.

    If despite these warnings you still want to give it a shot anyway, great. But you are on your own to troubleshoot and analyse any problems (the thread I linked is proof of the skill set depth you're going to need; the patch_files stuff that's unique to FreshTomato is a good example), and solve them in a way that continues works on the distro used per the, if you wish to contribute your work back upstream.

    This sounds a bit brash/harsh, but you're going to be expected to review the Makefile (and things they include), their targets, etc. to try and figure out what does what. It's not documented and there's basically no comments anywhere, so reverse-engineering everything is pretty much par for the course every step of the way.

    Welcome to present-day Linux where nothing is consistent! :)
    Last edited: Aug 30, 2018
    AndreDVJ likes this.
  3. moffa

    moffa Addicted to LI Member

    The problem you will have is that arch being a rolling distro will use a newer version of gcc. With gcc 7, you get a bunch of errors that you have to work your way through. It's a pretty big headache and I don't recommend it.
  4. Cold Winter

    Cold Winter Networkin' Nut Member

    Thanks to you and Koitsu.

    The problems go beyond Tomato as well. Even with OpenWRT and its supposed
    ability to compile under ARCH, I find that there are some apps that appear
    to be uncompilable with GCC 8 ( current on Arch ) because of deprecated

    Mind you with the Debian V9 VM I'm also using it isn't all that smooth either ;)

    Trick question; is there some way to force make to use GCC 5 ... that is available
    under Arch ? it would be a lot quicker than editing every makefile there is.
  5. cobrax2

    cobrax2 Serious Server Member

    well i've experimented a bit with building freshtomato for r6400v2, managed to compile it, but something went wrong
    i used make with initial, and then the normal one, flashed them and bricked the router, ofc lol
    debricked via serial, then looked in a hex viewer at the firmwares, the initial one had the same first bytes as a normal prebuilt by @kille72 , the normal one had something totally different, dunno why. the log in putty showed that it tries to boot but the image has something wrong with it. anyways, it goes into bootloop.
    flashed factory image and going to wait a bit for someone with more knowledge than me to compile it :)
  6. Cold Winter

    Cold Winter Networkin' Nut Member

    Maybe I'm wrong, but it looks like the git is pulling down Pedro311's actual development tree and
    not the actual release. So at any given point what we get when we do a git is pretty much
    up in the air. ;)

    If all you want is a working source tree of the last full release, maybe we should ask the devs
    if they can publish that separately?
  7. txnative

    txnative Addicted to LI Member

    Did you bother to check if the board_id where the same(r6400,r6400v2)the .chk initial image is to be used to place tomato onto your unit, if you didn't compile the r6400v2 initial chk then that would explain or one of the reasons why it failed, the sources are all the same kille72,pedro311,AndreDVJ etc for anyone to use and build but going off to add or make changes is on you to figure out, but it should be do able to do. Kille72 and pedro311 are the developers as their sources are updated and with other community members donating their time and skills to help out with this open source project to keep it alive. I congratulate you for taking the step into making the effort to adding and compile a new device. I know it's not easy it is time consuming, but worth it.

    Edited: I had a look at the source and it looks they are both identical(board_id)R6400 and R6400v2 except the versions
    Last edited: Dec 12, 2018
  8. txnative

    txnative Addicted to LI Member

    double post, browser froze
  9. cobrax2

    cobrax2 Serious Server Member

    thanks for answering me
    yes, i've modified (i think) in all the places i could find the board id, and the parameters from dd-wrt. i guess it isn't enough :)
    i'm not surprised it doesn't work, i just don't understand why the file header for the normal build is not the correct one
  10. txnative

    txnative Addicted to LI Member

    Which header are you referring? Unfortunately there isn't documentation on adding a device in this situation, you could use the example of how the r6400 is done, fill the blanks where the r6400 is, but you would be adding the data for the r6400v2. If you have dd-wrt installed you could find all info for board, vlan and you download sysinfo from svn dd-wrt for the wireless params, but you still have to compile the initial.chk image. I was going to assist but I don't have a r6400v2 but you'll need the board, vlan information either from a serial connection or if you have dd-wrt installed that would be helpful, beside If you'd like for someone compile it for you they would need the board,vlan information to get it use the command "nvram show | grep board" without the quotes, do the same for vlan as well. I may have missed looking through svn at the time(Edit:I found it). Post the board and vlan and if you need help further post again, Good luck
    Last edited: Dec 13, 2018
  11. tvlz

    tvlz LI Guru Member

    You can try things all you want but it still comes down to the BCM4708C revision of the chipset is not supported.

    It looks like @kille72 posted the needed SDK6 patches however the link expired and will need to reposted.

    There are still problems with setting the default nvram values after those patches so until those are fixed newer routers that use the BCM4708C/BCM4709C revision of the chipset won't work.
  12. txnative

    txnative Addicted to LI Member

    I thought about that to, but why not it'll give the guy an experience to building it later when the proper sdk comes out but that will depend if it does or not now.
  13. pedro311

    pedro311 Networkin' Nut Member

    Nope, the patch was incomplete, and when it was used, you didn't have WL at all...
    M_ars, txnative and kille72 like this.
  14. cobrax2

    cobrax2 Serious Server Member

    it becomes a bit too technical for me :)
    what is this sdk6?
    all i did was replace in the source all the instances of the board and parameters of r6400 with the ones from r6400v2 i took from ddwrt. but some parameters were on tomato, some were not, also the other way around.
    so i guess that's why it didn't work. i just don't understand why it wont even boot, and why the file headers are not the same. by file headers i mean the first hex bytes that you see in a file. the initial one has the correct headers, the normal one does not. oh well. it's well above my paygrade
  15. jorkki

    jorkki New Member Member

    I have a noob build question as well.

    I decided to try the build process so I installed Virtualbox 6.0.4 and the latest Debian Linux 9 (kernel, gcc Debian 6.3.0-18+deb9u1).
    I installed the packages and paths as per Kille's instructions on the overview page of the repository but as I wanted to see if I will get exactly the same 2019.1 image for my AC3200 that is downloadable from the web, I went to Tags in the downloads section and selected the v2019.1 (commit 2d8a087) for download.

    The build process seemed to go fairly well. I should probably have captured all the messages to see more closely.
    In the end I got this:

    [=========...==============================================\] 1331/1331 100%
    Exportable Squashfs 4.0 filesystem, xz compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments, compressed xattrs
    duplicates are removed
    Filesystem size 9372.23 Kbytes (9.15 Mbytes)
    35.73% of uncompressed filesystem size (26233.67 Kbytes)
    Inode table size 10308 bytes (10.07 Kbytes)
    21.23% of uncompressed inode table size (48559 bytes)
    Directory table size 12580 bytes (12.29 Kbytes)
    45.54% of uncompressed directory table size (27623 bytes)
    Number of duplicate files found 70
    Number of inodes 1475
    Number of files 1204
    Number of fragments 63
    Number of symbolic links 211
    Number of device nodes 0
    Number of fifo nodes 0
    Number of socket nodes 0
    Number of directories 60
    Number of ids (unique uids + gids) 1
    Number of uids 1
    root (0)
    Number of gids 1
    root (0)
    ctools/trx -o image/linux-lzma.trx ctools/vmlinuz-lzma ctools/target.squashfs
    ctools/trx_asus -i image/linux-lzma.trx -r RT-AC3200,,image/freshtomato-RT-AC3200-ARM-2019.1-"VPN-128K".trx

    Creating ASUS RT-AC3200 firmware to image/freshtomato-RT-AC3200-ARM-2019.1-VPN-128K.trx

    TRX Image:
    Total Size .... : 11366400 (11100.0 KB) (10.8 MB)
    CRC-32 ........ : F6FE29F1

    The original freshtomato-RT-AC3200-ARM-2019.1-VPN-128K.trx file by Kille, however is 11362304 bytes.
    I have not had the cohones yet to try the file, I decided to ask first before bricking the router.
    Any ideas why I got a file that is (suspiciously) exactly 4096 bytes larger?

  16. jorkki

    jorkki New Member Member

    Come to think of it, as it is a compressed file system and the dates and times of the generated files are different, for sure the CRC will be different as well. The 4k size difference probably relates to some block size used in compression?
    Is there a way to compare the actual files in the different .trx:s easily?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice