Thursday 24 March 2016

Install the ARM cross compiler toolchain on your Linux Ubuntu PC


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:
    sudo apt-get install gcc-arm-linux-gnueabi
    
    Install command for gnueabihf:
    sudo apt-get install gcc-arm-linux-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

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:
cd ~/<my_working _directory>
git clone https://github.com/Itseez/opencv.git

Building OpenCV

  1. Create a build directory, make it current and run the following command:
    cmake [<some optional parameters>] -DCMAKE_TOOLCHAIN_FILE=<path to the OpenCV source directory>/platforms/linux/arm-gnueabi.toolchain.cmake <path to the OpenCV source directory>
    
    Toolchain uses gnueabihf EABI convention by default. Add -DSOFTFP=ON cmake argument to switch on softfp compiler.
    cmake [<some optional parameters>] -DSOFTFP=ON -DCMAKE_TOOLCHAIN_FILE=<path to the OpenCV source directory>/platforms/linux/arm-gnueabi.toolchain.cmake <path to the OpenCV source directory>
    
    For example:
    cd ~/opencv/platforms/linux
    mkdir -p build_hardfp
    cd build_hardfp
    
    cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
    
  2. Run make in build (<cmake_binary_dir>) directory:
    make
    
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 for menuconfig.
  • 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

References



Raspberry Pi Wireless Hotspot:

What does it do?
This project configures your Raspberry Pi to connect to the Internet through ethernet, and share that connection over WiFi.
What do you need?
·        A Raspberry Pi, model B.
·        A boot SD card for the Raspberry Pi.
·        A USB WiFi device that supports "Access Point" mode.
·        An Ethernet cable to connect to the local network.
Please make sure you Wifi dongle supports Access Point or Master Mode
·        Edimax does NOT support Access Point (UPDATE 8/22/15: Edimax DOES support Access point. Updated project has rtl drivers in hostapd 2.4: Raspberry Hotspot with Edimax USB WiFi Adapter)
·        AirLink 101 / AWL5088 does NOT support Access Point
·        Panda Ultra, Mid-Range and 300Mbps Wireless N adapters support Access Point
·        Ralink RT5370 and RT5372 DO support Access Point
What skill level is required?
This project does not require any coding or compilation. Very basic Linux and networking knowledge would be useful, but not essential.
To edit a configuration file (for example /etc/udhcpd.conf) use the following command
sudo nano /etc/udhcpd.conf
You will find yourself in a simple editor. Move around using the arrow keys. To save the file press Ctrl-o. To exit press Ctrl-x.
How does it work?
The Raspberry Pi is configured as a WiFi Hotspot, just like you would see in an internet cafe. It allows you to connect to the internet over WiFi using the Raspberry Pi as the bridge to the internet. The basic steps are
·        Enable a WiFi Access Point and broadcast on the channel of your choice
·        Assign dynamic IP addresses to any device that connects to WiFi network
·        Join the WiFi and Ethernet networks together by using Network Address Translation
Instructions
The following steps were performed on Raspbian but should be much the same on any Debian-based distro.
1. Install the necessary software.
sudo apt-get install hostapd udhcpd
2. Configure DHCP. Edit the file /etc/udhcpd.conf and configure it like this:
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds
Edit the file /etc/default/udhcpd and change the line:
DHCPD_ENABLED="no"
to
#DHCPD_ENABLED="no"
You will need to give the Pi a static IP address with the following command:
sudo ifconfig wlan0 192.168.42.1
To set this up automatically on boot, edit the file /etc/network/interfaces and replace the line "iface wlan0 inet dhcp" to:
iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
If the line "iface wlan0 inet dhcp" is not present, add the above lines to the bottom of the file.
Change the lines (they probably won't all be next to each other):
allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
to:
#allow-hotplug wlan0
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
3. Configure HostAPD. You can create an open network, or a WPA-secured network. A secure network is recommended to prevent unauthorized use and tampering, but you can also create an open network. To create a WPA-secured network, edit the file /etc/hostapd/hostapd.conf (create it if it doesn't exist) and add the following lines:
interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Change ssid=, channel=, and wpa_passphrase= to values of your choice. SSID is the hotspot's name which is broadcast to other devices, channel is what frequency the hotspot will run on, wpa_passphrase is the password for the wireless network. For many, many more options see the file /usr/share/doc/hostapd/examples/hostapd.conf.gz
If you would like to create an open network, put the following text into /etc/hostapd/hostapd.conf:
interface=wlan0
ssid=My_AP
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0
Change ssid= and channel= to values of your choice. Note that anyone will be able to connect to your network, which is generally not a good idea. Also, some regions will hold an access point's owner responsible for any traffic that passes though an open wireless network, regardless of who actually caused that traffic.
Edit the file /etc/default/hostapd and change the line:
#DAEMON_CONF=""
to:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
4. Configure NAT (Network Address Translation). NAT is a technique that allows several devices to use a single connection to the internet. Linux supports NAT using Netfilter (also known as iptables) and is fairly easy to set up. First, enable IP forwarding in the kernel:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
To set this up automatically on boot, edit the file /etc/sysctl.conf and add the following line to the bottom of the file:
net.ipv4.ip_forward=1
Second, to enable NAT in the kernel, run the following commands:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
These instructions don't give a good solution for rerouting https and for URLs referring to a page inside a domain, like www.nu.nl/38274.htm. The user will see a 404 error. Your Pi is now NAT-ing. To make this permanent so you don't have to run the commands after each reboot, run the following command:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Now edit the file /etc/network/interfaces and add the following line to the bottom of the file:
up iptables-restore < /etc/iptables.ipv4.nat
5. Fire it up! Run the following commands to start the access point:
sudo service hostapd start
sudo service udhcpd start
Your Pi should now be hosting a wireless hotspot. To get the hotspot to start on boot, run these additional commands:
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
At the completion of these instructions, your Pi should be providing a wireless network and allowing other devices to connect to the Internet. From my experience, the Pi makes a decent access point, although with cheaper WiFi dongles range will be fairly limited. I haven't stress tested this setup, but it seems to work fairly well and is handy when a "real" access point isn't available. I wrote most of the instructions from memory, if you find any errors/typos I'll correct them.
This tutorial originally was a post on the Raspberry Pi forum here, you can reply to that topic if you have issues. Thanks go to all the people who tested my tutorial on the forum, and to poing who contributed the WPA HostAPD config.

Please make sure you Wifi dongle supports Access Point or Master Mode
·        Edimax doesn't support Access Point (UPDATE 8/22/15: Edimax DOES support Access point, hostapd 2.4 with rtl driver: Hostapd-rtl8188)
·        AirLink 101 / AWL5088 doesn't support Access Point
·        Panda Ultra, Mid-Range and 300Mbps Wireless N Adapters support Access Point

·        Ralink RT5370 supports Access Point