This article illustrates how to install on a Ubuntu Linux PC the complete toolchain to cross compile the Linux Kernel, the Linux device drivers, the Linux applications and the boot loader like as AT91Bootstrap and its derivates like AcmeBoot and AriaBoot.
This procedure has been tested on Linux Ubuntu 15.04.
Install the Cross Compilers, utilities, etc.
Install the GCC, G++ cross compilers and support programs by typing:
$ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross $ sudo apt-get install binutils-arm-linux-gnueabi $ sudo apt-get install libncurses5-dev
If you are using an Arietta, Aria or FOX board:
$ sudo apt-get install gcc-arm-linux-gnueabi $ sudo apt-get install g++-arm-linux-gnueabi
If you are using an Acqua board:
$ sudo apt-get install gcc-arm-linux-gnueabihf $ sudo apt-get install g++-arm-linux-gnueabihf
Now you are ready to cross-compile on your PC all the source available for the Acme Boards based on Atmel MPUs.
Try the cross C compiler
Let's try to cross compile a Hello World example in C and running it on an Acme board.
This is the example:
#include "stdio.h" int main(void) { printf("Hello world !\n"); return 0; }
Compile it typing:
~$ arm-linux-gnueabi-gcc hello.c -o hello
As you can see we are using the ARM version of gcc just installed on your PC. It will generate an executable file for your Linux board.
Copy the executable file on the board via ssh:
~$ scp hello root@[your_board_ip]:/root
Then open a command session on your board and run the example:
~# ./hello Hello world !
Try the cross C++ compiler
Let's try to cross compile a Hello World example in C++ and running it on an Acme board.
This is the example:
#include "iostream" using namespace std; int main(int argc, char *argv[]) { cout << "Hello world !" << endl; return 0; }
Compile it typing:
~$ arm-linux-gnueabi-g++ hello.cc -o hello
As you can see we are using the ARM version of gcc just installed on your PC. It will generate an executable file for your Linux board.
Copy the executable file on the board via ssh:
~$ scp hello root@[your_board_ip]:/root
Then open a command session on your board and run the example:
~# ./hello Hello world !
ONE MORE METHOD IS BELLOW ID FIRST ONE NOT WORKED THEN JUST GO FOR SECOND METHOD:
Cross compilation for ARM based Linux systems
This steps are tested on Ubuntu Linux 12.04, but should work for other Linux distributions. I case of other distributions package names and names of cross compilation tools may differ. There are several popular EABI versions that are used on ARM platform. This tutorial is written for gnueabi and gnueabihf, but other variants should work with minimal changes.
Prerequisites
Host computer with Linux; Git; CMake 2.6 or higher; Cross compilation tools for ARM: gcc, libstc++, etc. Depending on target platform you need to choose gnueabi or gnueabihf tools. Install command for gnueabi:Install command for gnueabihf: pkgconfig; Python 2.6 for host system; [optional] ffmpeg or libav development packages for armeabi(hf): libavcodec-dev, libavformat-dev, libswscale-dev; [optional] GTK+2.x or higher, including headers (libgtk2.0-dev) for armeabi(hf); [optional] libdc1394 2.x; [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev for armeabi(hf).
Getting OpenCV Source Code
You can use the latest stable OpenCV version available in sourceforge or you can grab the latest snapshot from our Git repository.
Getting the Latest Stable OpenCV Version
- Go to our page on Sourceforge;
- Download the source tarball and unpack it.
Getting the Cutting-edge OpenCV from the Git Repository
Launch Git client and clone OpenCV repository
In Linux it can be achieved with the following command in Terminal:
Building OpenCV
- Create a build directory, make it current and run the following command:Toolchain uses gnueabihf EABI convention by default. Add -DSOFTFP=ON cmake argument to switch on softfp compiler.For example:
- Run make in build (<cmake_binary_dir>) directory:
Note
Optionally you can strip symbols info from the created library via install/strip make target. This option produces smaller binary (~ twice smaller) but makes further debugging harder.
Enable hardware optimizations
Depending on target platform architecture different instruction sets can be used. By default compiler generates code for armv5l without VFPv3 and NEON extensions. Add -DENABLE_VFPV3=ON to cmake command line to enable code generation for VFPv3 and -DENABLE_NEON=ON for using NEON SIMD extensions.
TBB is supported on multi core ARM SoCs also. Add -DWITH_TBB=ON and -DBUILD_TBB=ON to enable it. Cmake scripts download TBB sources from official project site http://threadingbuildingblocks.org/ and build it.
How do I cross-compile the kernel on a Ubuntu host?
Preparation
First, we need to install the required prerequisites. I assume you have
sudo
access.sudo apt-get install git ncurses-dev make gcc-arm-linux-gnueabi
git
is the version control system used by the Linux kernel team.ncurses
is a library for build console menus. It is necessary formenuconfig
.make
runs the compilation for us.gcc-arm-linux-gnueabi
is the cross-compiler.
Next, we need to retrieve the source, run:
git clone https://github.com/raspberrypi/linux raspberrypi-linux
cd raspberrypi-linux
This will clone the source code to a directory called
raspberrypi-linux
and change to it.Compilation
We first need to move the config file by running
cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
Then configure the kernel build
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
Optional: Customise the build using menuconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
Then run the compilation
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-gcc -k