Toolchain

From MiOS
Revision as of 08:58, 30 April 2012 by Ap15e (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Source: http://forum.micasaverde.com/index.php/topic,8910.msg71562.html#msg71562

Toolchain for Vera V2

By far, the easiest way is to let OpenWRT build one. That is ultimately what I had to do for the Vera 2 toolchain. There are some really good instructions on how to build OpenWRT here: http://wiki.openwrt.org/doc/howto/build

There is one change that you need to make to the instructions to get a proper build for the Vera 2. When you are told to run:

  svn co svn://svn.openwrt.org/openwrt/trunk/

You actually want to run:

  svn co -r 21639 svn://svn.openwrt.org/openwrt/trunk/

You will want to double check the revision number. It is either 21639 or 21638. If you SSH in to a Vera 2, in the banner screen you will see a version line indicating it is running OpenWRT Backfire 10.3 (rXXXXX). Where the XXXXX is the number you want.

Then, when you get to the "make menuconfig" command, under "Target System" you want to select "Broadcom BCM947xx/953xx [2.4]". That should be the only change you need to make. Then, run "make" and go take a nap. It will take some time to compile.

The instructions from OpenWRT on how to use the newly created tool-chain are really only useful if your project only uses a standard Makefile. If you are using an autoconf project, you need to just change the way you call configure. In a nutshell, you need to tell configure where to find the cross compiler(s) and linker. To do that, I pass arguments to ./configure. I believe you can also set environment variables, but I have not tried that. The ugly command line that I use is:

  ./configure CC=/home/chris/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1/usr/bin/mipsel-openwrt-linux-uclibc-gcc CXX=/home/chris/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1/usr/bin/mipsel-openwrt-linux-uclibc-g++ --host=x86_64-unknown-linux LD=/home/chris/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1/usr/bin/mipsel-openwrt-linux-uclibc-ld

Buried in there is a --host option. You will want to change that if your host machine isn't an x86_64. If you are only doing C code, you can skip using the CXX parameter, or if you are only doing C++ code, you can skip the CC parameter. I include both in case I mix some code later on. Also, you will want to make sure that you change the paths that are used, unless you home directory is also /home/chris.

After running that ugly configure command, running "make" will kick off the build with the cross-compiler chain. Keep in mind that if you have previously built the program to run on a different type of CPU, you will want to run a "make distclean" and rerun the autotools to get a clean build. As part of my build process, I have a shell script that handles all of this for me. It looks like this:

  make distclean
  autoconf;automake
  ./configure CC=/home/chris/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1/usr/bin/mipsel-openwrt-linux-uclibc-gcc CXX=/home/chris/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1/usr/bin/mipsel-openwrt-linux-uclibc-g++ --host=x86_64-unknown-linux LD=/home/chris/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1/usr/bin/mipsel-openwrt-linux-uclibc-ld
  make -j8

You may want to change the -j8 option on "make". Usually a good number is the number of cores in your machine *2. Since I build on a quad core machine, I use -j8. When your build is done, you can verify that it built for the MIPS platform by running "file <your_binary_name>". It should return that the file is a MIPS file.

My code doesn't use any libraries beyond uClibc. If you do, then you will probably need to set LD_LIBRARY_PATH to the directory that contains the cross compiled libraries you use. You will probably have to hack up your makefile a bit to point to the proper includes directory.

Toolchain for Vera V3

The easiest way to get a toolchain for the Vera 3 is basically the same thing as the 2. The one difference is we don't know the SVN revision that is being used by MCV to develop their stuff. However, I suspect that using the trunk version of OpenWRT will allow you to get builds for the Vera 3. However, I ended up using ct-ng to get my Vera 3 toolchain. I went through the tutorial on the ct-ng site, but tweaked the kernel version to be the closest one to the kernel on the Vera 3, and set it up to build uClibc. Then, in my build system I link everything as static, so I shouldn't hit any weirdness with library revisions on the Vera 3. (At the expense of a little bit more space used on the flash.)

Personal tools