Cross Compile Guide for TS 7800 - FREEDM-DGI/FREEDM GitHub Wiki
This article is for crosstool-ng 1.17 on Archlinux. An article for Ubuntu 12.04 LTS is available: Cross Compile (Ubuntu 12.04)
Compiling FREEDM on the TS-7800 takes a long time. We can do it faster by cross compiling! Building the enivronment takes a little while but the compile times are much better by a large factor, so It should be worth it.
I am assuming you are using the 2.6.34 kernel provided for the TS-7800. It is my understanding it is the only one you can get boost working on.
What you need:
- A copy of the source tarball for the kernel for the TS-7800. You can grab it from this link
- A copy of crosstool-ng installed on your system. On Archlinux it is available from AUR so I assume it is available via Apt on debian and ubuntu. My version was 1.17.0. Other versions may not have the correct versions of the various libraries, YMMV.
- An internet connection on the machine you are building crosstool on
- g++, gcc, and subversion.
Cross compilation is supported beginning with FREEDM v1.3.
- make a
ts7800folder in your home directory. This will serve as the staging area for building the cross compiler. Collecting everything takes about 3.5GB, so keep that in mind. - Put the
2.6.34.tar.gzfile (the source tarball for the TS-7800 kernel) in this folder. - Invoke
ct-ng menuconfigfrom inside the ts7800 folder. - Go into the Paths and Misc options menu and select "Try features marked as EXPERIMENTAL"
- Go back to the main menu and then into the Target Options menu. Confirm the following settings
- Target architecture is arm
- Endianness is Little Endian
- the Bitness is 32-bit
- Use EABI is selected
- Set the architecture Level to be
armv5t - Select the line that says "Floating Point (hardware)" and select to software.
- Operating System Menu
- Target OS should be set to linux.
- Select the linux kernel version menu, then scroll to the bottom and choose "Custom Tarball or Directory" enter the path to the 2.6.34.tar.gz file (should be
/home/xxxx/ts7800/2.6.34.tar.gz) - Select build shared libraries
- Check installed headers.
- Go into the binary utilities menu.
- Select binutils version 2.22
- Go into the C compiler menu
- Select GCC version 4.5.3
- Select C++ as an additional language
- Go into the C-Libray menu
- Select glibc version 2.13
- Exit and save the configuration. Build to toolchain by invoking
ct-ng buildThis part takes awhile. - Unless you changed the prefix from
${HOME}/x-tool/${CT_TARGET}you should add${HOME}/x-tools/arm-unknown-linux-gnueabi/bin/to your PATH. You can do this for one session by doingexport PATH=$PATH:${HOME}/x-tools/arm-unknown-linux-gnueabi/bin/adding this to.bashrcor similar will make it permanent.
Because FREEDM does use some of the compiled boost headers, you'll need to cross-compile boost to be able to build FREEDM. We recommend boost version 1.49, and these directions are for that version.
- Download Boost 1.49 and extract it to your home directory, making a boost_1_49 directory.
- Go into the freshly extracted boost folder.
- Invoke
./bootstrap.shin that folder, this will build boost jam for you. - Edit
tools/build/v2/user-config.jamand addusing gcc : arm : arm-unknown-linux-gnueabi-g++ ;to the top of the file. - Ensure the cross-compilers are on your path:
export PATH=$PATH:${HOME}/x-tools/arm-unknown-linux-gnueabi/bin/ - Invoke
b2which will build Boost.
You will need to set BOOST_ROOT to point to this particular Boost folder whenever you compile. More details on that below.
Protocol buffers require the protocol buffers library to be installed on the target system. It is important to have the same version of protocol buffers on your build system as on the target system. On my system the protocol buffers version was 2.6.1
- Verify the version of protocol buffers installed on your system using
protoc --version - Download the source of the protocol buffers version you have installed and extract it.
- Ensure the cross-compilers are on your path:
export PATH=$PATH:${HOME}/x-tools/arm-unknown-linux-gnueabi/bin/ - Inside the source folder invoke
./configure CC=arm-unknown-linux-gnueabi-gcc CXX=arm-unknown-linux-gnueabi-g++ --host=arm-linux --with-protoc=protoc --prefix=${HOME}/x-tools/arm-unknown-linux-gnueabi/protobuf/.prefixshould be a folder where the resulting libraries can be placed after compilation. - Build the protocol buffers library with
make. - Invoke
make installto place the compiled libraries in the folder you specified withprefix - Copy the contents of the lib folder in your prefix directory to the TS7800
${HOME}/x-tools/arm-unknown-linux-gnueabi/protobuf/libto your TS7800's/usr/libfolder. You should be copying several libprotobuf files.
Make note of the prefix directory you put the files in, you'll need it to compile FREEDM.
Now that you have crosstool and boost built, you can compile FREEDM. You will need to feed some additional options to CMake so I recommend preparing a crosscompile.sh in your Broker directory. Here is mine:
#!/bin/sh
export PATH=$PATH:/home/scj7t4/x-tools/arm-unknown-linux-gnueabi/bin/
export BOOST_ROOT=/home/scj7t4/programming/ts7800/boost_1_49_0
CC=arm-unknown-linux-gnueabi-gcc CXX=arm-unknown-linux-gnueabi-g++ cmake -DPROTOBUF_LIBRARY=/home/scj7t4/x-tools/arm-unknown-linux-gnueabi/protobuf/lib/libprotobuf.so -DPROTOBUF_INCLUDE_DIR=/home/scj7t4/x-tools/arm-unknown-linux-gnueabi/protobuf/include/
make -j4
You'll need to change the paths to match your environment, particularly, the location where you built boost, the path to where you placed the protocol buffers, and your home directory
This has the advantage of not muddling up your normal environment, since it only sets BOOST_ROOT for the purpose of compiling (environment variables are reset when the script exits) it is safe to use this method when you also need to compile boost natively on the same system.
Here is the procedure for cross compiling, step by step.
- Ensure that your cross-compiling tool chain is on your path. This is done by setting the path variable.
- Ensure that BOOST-ROOT points to the boost you built earlier. (This only works if the distribution's boost package is NOT installed)
- Run CMake with specific compiler targets. The
CC=andCCX=instruct cmake to use the gcc and g++ cross compilers you prepared earlier. - Invoke make.
- Copy your new binary to the ARM board. You'll still need to have a config folder with the appropriate config files.
Enjoy! On my system, compiling FREEDM takes about 5 minutes vs. several hours to build it on the ARM board.