Jessie armhf Cross Compile: Difference between revisions

From embeddedTS Manuals
No edit summary
m (Non-link text auto-updated for 2022 re-branding ( http://ftp.embeddedarm.com/ftp/ts-arm-sbc/ts-7553-V2-linux/cross-toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz →‎ http://ftp.embeddedTS.com/ftp/ts-arm-sbc/ts-7553-V2-linux/cross-toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz))
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Debian Jessie provides cross compilers, but it does require a Debian Jessie system to be used for the workstation. A PC, virtual machine, or chroot will need to be used for this.  Download Debian Jessie for your workstation [https://www.debian.org/releases/jessie/ here].
Debian Jessie previously provided cross compilers via the Emdebian project. However, Emdebian has been unmaintained for a number of years and is no longer able to provide a viable install package. In order to cross compile from a Debian Jessie workstation, a third party cross compiler is required.


From your workstation (not the board), run these commands to set up the cross compiler:
A Debian Jessie install on a workstation has the ability to build for the same release on other architectures using Debian binary libraries.  A PC, virtual machine, or chroot will need to be used for this.  Install Debian Jessie for your workstation [https://www.debian.org/releases/jessie/ here].
 
From a Debian workstation (not the target), run the following commands to set up the cross compiler. Note that this expects a 64-bit Debian Jessie install on the workstation. 32-bit installations are not supported at this time.
<source lang=bash>
<source lang=bash>
# Run "lsb_release -a" and verify Debian 8.X is returned.  These instructions are not
# Run "lsb_release -a" and verify Debian 8.X is returned.  These instructions are not
# expected to work on any other version or distribution.
# expected to work on any other version or distribution.


apt-get install curl build-essential
cd ~
 
wget http://ftp.embeddedTS.com/ftp/ts-arm-sbc/ts-7553-V2-linux/cross-toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
# The above toolchain is from Linaro. Other cross compilers can be used but have not been tested.
mkdir cross_compiler
tar xvf gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz -C ~/cross_compiler
export PATH=$PATH:~/cross_compiler/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf/bin/
# The 'export' command needs to be run every time the user logs in. It is possible to add this command to the user's ".bashrc" file
# in their home directory to ensure it is automatically run every time the user is logged in.
su root
su root
echo "deb http://emdebian.org/tools/debian jessie main" > /etc/apt/sources.list.d/emdebian.list
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
dpkg --add-architecture armhf
dpkg --add-architecture armhf
apt-get update
apt-get update
apt-get install crossbuild-essential-armhf
apt-get install build-essential
</source>
</source>
This will install a toolchain you can use with the prefix "arm-linux-gnueabihf-".  All of the standard GCC tools will start with that name, eg "arm-linux-gnueabihf-gcc".
This will install a toolchain that can be used with the prefix "arm-linux-gnueabihf-".  The standard GCC tools will start with that name, eg "arm-linux-gnueabihf-gcc".


You can test out thet toolchain with a hello world.  Create your hello-world.c with your preferred editor:
The toolchain can now compile a simple hello world application.  Create hello-world.c on the Debian workstation:
<source lang=c>
<source lang=c>
#include <stdio.h>
#include <stdio.h>
Line 29: Line 35:
file hello-world
file hello-world
</source>
</source>
This will return that the binary created is for ARM.  Copy this to the armhf distribution to run it there.
This will return that the binary created is for ARM.  Copy this to the target platform to run it there.
 
Debian Jessie supports multiarch which can install packages designed for other architectures.  On workstations this is how 32-bit and 64-bit support is provided.  This can also be used to install armhf packages on an x86 based workstation.
 
This cross compile environment can link to a shared library from the Debian root.  The package would be installed in Debian on the workstation to provide headers and ".so" files.  This is included in most "-dev" packages.  When run on the arm target it will also need a copy of the library installed, but it does not need the -dev package. Note that since the cross compiler used is 3rd party and not directly from Debian, some compile commands that include libraries will need additional arguments to tell the compiler and linker where on the workstation to find the necessary headers and libraries. Usually, the additional arguments will look like the following string, however adjustments may need to be made depending on the application.
  -I/usr/include -L/usr/lib/arm-linux-gnueabihf -L/lib/arm-linux-gnueabihf -Wl,-rpath=/usr/lib/arm-linux-gnueabihf,-rpath=/lib/arm-linux-gnueabihf
 


Now to link to a shared library from the Debian environment.  Make sure the package you are linking to is installed on both your debian workstation and the board.  Since the armhf architecture was added earlier you can install armhf packages on your x86 workstation.
<source lang=bash>
<source lang=bash>
apt-get install libcurl4-openssl-dev:armhf
apt-get install libcurl4-openssl-dev:armhf
Line 37: Line 48:
# Download the simple.c example from curl:
# Download the simple.c example from curl:
wget https://raw.githubusercontent.com/bagder/curl/master/docs/examples/simple.c
wget https://raw.githubusercontent.com/bagder/curl/master/docs/examples/simple.c
# After installing the supporting library, curl will link just as compiling on the unit.
# After installing the supporting library, curl will link as compiling on the unit.
arm-linux-gnueabihf-gcc simple.c -o simple -lcurl
arm-linux-gnueabihf-gcc -I/usr/include -L/usr/lib/arm-linux-gnueabihf -L/lib/arm-linux-gnueabihf -Wl,-rpath=/usr/lib/arm-linux-gnueabihf,-rpath=/lib/arm-linux-gnueabihf simple.c -o simple -lcurl
</source>
</source>
Copy the binary to the target platform and run on the target.  This can be accomplished with network protocols like NFS, SCP, FTP, etc.


You should be able to execute this from the board now. Using the curl library that will be loaded at runtime from the board.
If any created binaries do not rely on hardware support like GPIO or CAN, they can be run using qemu.
 
If your binaries do not rely on hardware support like GPIO or CAN, you can run your binaries using qemu.
<source lang=bash>
<source lang=bash>
# using the hello world exampel from before:
# using the hello world example from before:
./hello-world
./hello-world
# Returns Exec format error
# Returns Exec format error

Latest revision as of 14:19, 18 January 2022

Debian Jessie previously provided cross compilers via the Emdebian project. However, Emdebian has been unmaintained for a number of years and is no longer able to provide a viable install package. In order to cross compile from a Debian Jessie workstation, a third party cross compiler is required.

A Debian Jessie install on a workstation has the ability to build for the same release on other architectures using Debian binary libraries. A PC, virtual machine, or chroot will need to be used for this. Install Debian Jessie for your workstation here.

From a Debian workstation (not the target), run the following commands to set up the cross compiler. Note that this expects a 64-bit Debian Jessie install on the workstation. 32-bit installations are not supported at this time.

# Run "lsb_release -a" and verify Debian 8.X is returned.  These instructions are not
# expected to work on any other version or distribution.

cd ~
wget http://ftp.embeddedTS.com/ftp/ts-arm-sbc/ts-7553-V2-linux/cross-toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
# The above toolchain is from Linaro. Other cross compilers can be used but have not been tested.
mkdir cross_compiler
tar xvf gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz -C ~/cross_compiler
export PATH=$PATH:~/cross_compiler/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf/bin/
# The 'export' command needs to be run every time the user logs in. It is possible to add this command to the user's ".bashrc" file
# in their home directory to ensure it is automatically run every time the user is logged in.
su root
dpkg --add-architecture armhf
apt-get update
apt-get install build-essential

This will install a toolchain that can be used with the prefix "arm-linux-gnueabihf-". The standard GCC tools will start with that name, eg "arm-linux-gnueabihf-gcc".

The toolchain can now compile a simple hello world application. Create hello-world.c on the Debian workstation:

#include <stdio.h>
int main(){
    printf("Hello World\n");
}

To compile this:

arm-linux-gnueabihf-gcc hello-world.c -o hello-world
file hello-world

This will return that the binary created is for ARM. Copy this to the target platform to run it there.

Debian Jessie supports multiarch which can install packages designed for other architectures. On workstations this is how 32-bit and 64-bit support is provided. This can also be used to install armhf packages on an x86 based workstation.

This cross compile environment can link to a shared library from the Debian root. The package would be installed in Debian on the workstation to provide headers and ".so" files. This is included in most "-dev" packages. When run on the arm target it will also need a copy of the library installed, but it does not need the -dev package. Note that since the cross compiler used is 3rd party and not directly from Debian, some compile commands that include libraries will need additional arguments to tell the compiler and linker where on the workstation to find the necessary headers and libraries. Usually, the additional arguments will look like the following string, however adjustments may need to be made depending on the application.

 -I/usr/include -L/usr/lib/arm-linux-gnueabihf -L/lib/arm-linux-gnueabihf -Wl,-rpath=/usr/lib/arm-linux-gnueabihf,-rpath=/lib/arm-linux-gnueabihf


apt-get install libcurl4-openssl-dev:armhf

# Download the simple.c example from curl:
wget https://raw.githubusercontent.com/bagder/curl/master/docs/examples/simple.c
# After installing the supporting library, curl will link as compiling on the unit.
arm-linux-gnueabihf-gcc -I/usr/include -L/usr/lib/arm-linux-gnueabihf -L/lib/arm-linux-gnueabihf -Wl,-rpath=/usr/lib/arm-linux-gnueabihf,-rpath=/lib/arm-linux-gnueabihf simple.c -o simple -lcurl

Copy the binary to the target platform and run on the target. This can be accomplished with network protocols like NFS, SCP, FTP, etc.

If any created binaries do not rely on hardware support like GPIO or CAN, they can be run using qemu.

# using the hello world example from before:
./hello-world
# Returns Exec format error
apt-get install qemu-user-static
./hello-world