************************************************************** * How to Build the WAG354G firmware from sources * * v 0.4 * * Author: Marco Vedovati * * mailto: marco.v83@gmail.com * * http://cyberstorm.altervista.org/ * ************************************************************** * * * License: this guide is licensed under the * * Creative Commons Attribution-NonCommercial-ShareAlike 2.5 * * info @: http://creativecommons.org/licenses/by-nc-sa/2.5/ * * * ************************************************************** * As always, standard disclaimer: This is a free guide! * * I take no responsability for any loss, damage or injury * * arising from the use of it. * ************************************************************** This guide is available in the following languages: [EN] If you want, you can translate it it other language. Please let me know so that I can put it online. For errors (both grammatical and conceptual), succesful experiences or things I may have missed, contact me. Changelog: 0.4: fixed the "tar" command to extract .gz and .bzip2 files, told me by an anonymous user. 0.3: added a more complete list of packages, in case you use a very small linux distro, like dsl. 0.2: added advice on distro & a new error (thanks to Carciofone for error log & testing). 0.1: initial release (2007/02/12) Index: .Intro .Requirements .Here we go! ....Install the TI Toolchain ....Prepare the source ....Make .Troubleshooting ------- Intro: This is the ultimate step by step guide to compile source code of Linksys WAG354G adsl router (and probably even other Linksys models). -------- Requirements: * An x86 machine, because the toolchain we are gonna use is compiled for the x86 architecture. Probably is also possible to use an x86 virtual machine. * A running linux OS, but maybe also unix is ok. So far, I have successfully built source using Debian sid (http://debian.org/). If you are new to the linux world, and you have to choose a distro, I also suggest you to try ubuntu (http://www.ubuntu.com/). A (quite) complete list of tools needed is the following: build-essential (for debian&co) make rcs sed shellutils coreutils findutils fileutils debianutils (if non-debian look for a pkgz that contains "which" command) *binutils *gcc(x86 target) *automake *autoconf ncurses libncurses bison libstdc++6 libc6 *libc6-dev Most of these tools are already installed in every modern linux distro. So if you dont find a specific package, ignore it, unless you get some compile errors (see the Troubleshooting section for details). Tools signed with a (*) are probably not necessary for our goal. Anyway if you'll work in linux sooner or later you will need them. Also be SURE you doesn't have already installed another mispel-uclibc compiler. * The source code of wag354g. It can be found on the ftp of linksys, that is: ftp://ftp.linksys.com/opensourcecode/ In near future you will be able to grab already modified source code from my svn. Stay tuned for info on my website! * The TI toolchain. *Currently* one copy it's included here: ftp://anonymous@ftp.linksys.com/opensourcecode/wag54gv2/wag54gV2/1.00.19/WAG54GV2_V1.00.19_GPL.tgz. If not, try to dowload packages other big(>100MB) packages and check if there is the toolchain inside. -------- Here we go! 1) Install the TI Toolchain Open a terminal and change the directory where the WAG54GV2_V1.00.19_GPL.tgz package is located. In my case is located on my desktop. $ cd Desktop/ $ tar -xvzf WAG54GV2_V1.00.19_GPL.tgz Wait until it's decompressed. Now you have a folder called WAG54V2. $ cd WAG54GV2/ You can delete the src folder, it contains source code of wag54v2. $ rm -r src Now enter the tools folder: $ cd tools/ $ ls TI-toolchains-2_1_0-cy07-Redhat7_1.tgz TI-toolchains.README If you like, you can take a look at the README file, but I already report here the necessary step. You must be "root" to execute this command. Either do a: $ su [enter your password] Or, if it's not accepted (like on ubuntu) write "sudo" (without quotes) before every following commands. Enter: $ tar zxvf TI-toolchains-2_1_0-cy07-Redhat7_1.tgz -C /opt/ $ cd /opt $ ln -s TI-toolchains-2_1_0-cy07 cy $ exit (if you tyepd su before) Ok now our toolchain is installed. Close your terminal. --- 2) Prepare the source! I assume here you already have download the source code of the wag. If not, read the "Req" on top. Open once again the terminal and enter where in the directory where the source code package is located and extract the sources. In my case I have the WAG354G-EU-v1_01_11-00.tar.bz2 on Desktop: $ cd Desktop/ $ tar -xvjf WAG354G-EU-v1_01_11-00.tar.bz2 Once finished, enter in the sources folder: $ cd WAG354G-EU-v1_01_11-00 You can delete the tools-src folder: $ rm -r tools-src Now we have to set up the file permission correctly. Type (not as root!): $ chmod -R 755 src/ Enter in the src directory. If you are curious, take a look! Now comes an important thing. **EVERY TIME** you open a terminal to compile the firmware, first you have to type: $ export PATH=$PATH:/opt/cy/mipsfple/bin:/opt/cy/mipsfple-uclibc/bin This includes the toolchain binaries in the PATH environment variable. If you close and reopen the terminal, PATH is resetted to default. --- 3)Make! (it's better not to be root to compile sources). Assuming that you have already opened a terminal and typed: $ export PATH=$PATH:/opt/cy/mipsfple/bin:/opt/cy/mipsfple-uclibc/bin All you have to do is: $ ./make.sh After several minutes, if there are no errors, you should have in the image/ folder a file called "upgrade_code.bin" that is the firmware! -------- Troubleshooting Most of the time, you will get some errors during the first make processes. In this cases the informations about the last error we get is not useful since it depends most of the times from previous errors. To trace all the errors the best thing to do is redirect the output of the make into a file: $ ./make.sh > compile.log 2>&1 And the end of the make, we can open the compile.log file with a text editor. Errors can be find searching for the string "] erorr" and/or "error:" . I will now list some of the most common problems: 1) ... make[1]: mipsel-uclibc-gcc: Command not found ... Reason: This is because either you have not installed the toolchain correctly or not exported the PATH variable. Solution: Check that the toolchain is installed does exist in /opt/TI-toolchains-2_1_0-cy07 and that /opt/cy points to it. Do this with: $ cd /opt $ ls -l Also be sure you have done a: $ export PATH=$PATH:/opt/cy/mipsfple/bin:/opt/cy/mipsfple-uclibc/bin To check if the PATH is setted up correctly type: $ echo $PATH The output must contain :/opt/cy/mipsfple/bin:/opt/cy/mipsfple-uclibc/bin 2) .... make[#]: xxxxx: Command not found .... Reason: in your system is not installed the xxxxx program Solution: Search with your packet manager / google in which package the xxxxx program is, and install it. The list of packages at the top could help you. 3) /bin/sh: -c: line 6: syntax error near unexpected token `)' /bin/sh: -c: line 6: `fi )' make: *** [all] Error 2 This error can be resolved modifying src/router/Makefile. Open it, and search for "config_modules" You should find *2* lines like this: if [ "$${CONFIG_MODULES}" = "y" ] ; then \ In both cases, two lines beyond, there is this: fi ) \ Cange it in: fi ; \ 4) .... src/linux/linux/drivers/net/mac/writemac.o': No such file or directory make: *** [linux-modules] Error 1 .... This error is not influent, you can safely ignore it. 5) ... /opt/TI-toolchains-2_1_0-cy07/mipsfple/bin/../mipsel-hardhat-linux/bin/ld: cannot find -lnvram collect2: ld returned 1 exit status ... OR ... /opt/TI-toolchains-2_1_0-cy07/mipsfple/bin/../mipsel-hardhat-linux/bin/ld: cannot find -lshared collect2: ld returned 1 exit status make[1]: *** [httpd] Error 1 ... These are definetely strange errors. I think they depend on the Makefile being not interpreted in the right way by the shell. This behaviour has been enconuntered once on Mandriva. Solution(?): 1) Use bash as shell. 2) Be sure NOT to lauch the make as: $ sh make.sh but use instead $ ./make.sh 3) If all the above fail, reboot...:) ~~~~~~~~~~~~~~~~~~~~~~~THE END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~