Toolchain

TODO

Toolchain, cross-compilation

Building a custom cross-compilation toolchain using crostool-ng

Install deps (ubbuntu example, taken from crosstools-ng's testing Dockerfile ). Look into testing/docker/YOUR OS/Dockerfile for deps for your os:
apt install -y gcc g++ gperf bison flex texinfo help2man make libncurses5-dev \
    python3-dev autoconf automake libtool libtool-bin gawk wget bzip2 xz-utils unzip \
    patch libstdc++6 rsync git
Download and install ("locally") crosstool-ng:
git clone https://github.com/crosstool-ng/crosstool-ng
cd crosstool-ng/
./bootstrap
./configure --enable-local
make -j4
Run and configure ct-ng:
./ct-ng help
# list available configurations
./ct-ng list-samples
# select rpi 1/zero (armv6-rpi-linux-gnueabi for older crosstol-ng)
./ct-ng armv6-unknown-linux-gnueabihf
./ct-ng menuconfig
You might want to change the paths where sources are downloaded and the built toolchain is placed:
Paths and misc options  --->
  Local tarballs directory
  Prefix directory
You could also edit it directly in .config:
CT_LOCAL_TARBALLS_DIR="${HOME}/embeddedlinux/src/ct"
CT_PREFIX_DIR="${CT_PREFIX:-${HOME}/embeddedlinux/cross}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
Create the download dir, otherwise crosstool-ng won't really use it ;(
mkdir ../src/ct
Then tell ct-ng to actually build the toolchain
time ./ct-ng build
  ...
real    35m54.579s
user    226m9.764s
sys     19m53.080s
Used space:
$ du -sxhc crosstool-ng src/ct cross
13G     crosstool-ng
234M    src/ct
536M    cross
13G     total

Testing it

I told ct-ng to install it under ${HOME}/embeddedlinux/cross/..., so let's make it available in our $PATH:
export PATH=$PATH:$HOME/embeddedlinux/cross/bin/
Let's create a small test file test.c
#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("Hi there!");
    return 0;
}
and compile it
armv6-unknown-linux-gnueabi-gcc -o test test.c
Let's see what we got
$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, with debug_info, not stripped

$ ./test
-bash: ./test: cannot execute binary file: Exec format error

Resources

A nice, in depth description of how to build a crosscompiler completely manually can be found at https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/.
Vim logo FireFox logo CSS XHTML
Jozef Siska @ KAI FMFI UK YoYo @ KSP KAI (DAI) KSP