How to get toolchans

Submitted by Sergey Worm on Sat, 05/05/2018 - 19:17

WrmOS projects my be built by any toolchain based on GCC. Using toolchain is specifying in project configuration file. Since WrmOS is designed for realtime embedded projects, this article describes how to get cross-platform toolchains.

There are 2 ways to get toolchain:

  • download prebuilt toolchain;
  • build toolchain from sources.
Contents
1. Download toolchain
2. Build toolchain from sources
3. Build libm from sources

1. Download toolchain [up]


  1. Download archive with prebuilt toolchain:
  2. Extract archive and move toolchain directory to installation directory (for example ~/toolchain/).
  3. Add path to toolchain to your environment (see step 2.7 below from step-by-step manual).

2. Build toolchain from sources [up]


The easy way to get cross-platform toolchain is using of Buildroot project. Below you can find step-by-step manual how to download and build toolchain. This manual is common for all processor architectures. Differences are additional marked. Word $ARCH should be changed to target architecture.

Step-by-step

2.1. Clone Buildroot git repository:

git clone git://git.buildroot.net/buildroot
cd buildroot

2.2. Switch repository state to last release (use "git tag" to see list of tags):

git checkout 2018.02.2

2.3. Choose default configuration to based on it (this step is architecture depended):

SPARCv8:  make qemu_sparc_ss10_defconfig
ARM:      make qemu_arm_vexpress_defconfig
x86:      make qemu_x86_defconfig
x86_64:   make qemu_x86_64_defconfig

2.4. Tune configuration:

make menuconfig
    Build options --> libraries --> both static and shared
    Toolchain --> Enable WCHAR support
    Toolchain --> GCC compiler Version --> gcc 7.x
    Toolchain --> Enable C++ support --> on
    Toolchain --> Enable compiler link-time-optimization support --> on
    Toolchain --> Build cross gdb for the host --> on
    Target packages --> Libraries --> Other --> boost --> on
    Target packages --> Libraries --> Other --> boost-filesystem --> on
    Target packages --> Libraries --> Other --> boost-system --> on

2.5. Start building (it may take a few minutes):

make toolchain host-gdb boost

2.6. Copy result to installation directory (for example ~/toolchains/):

# ARCH = sparc | arm | i686 | x86_64
cp -r output/host/ ~/toolchains/$ARCH-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0

2.7. Add path to toolchain to your environment:

# ARCH = sparc | arm | i686 | x86_64
vi ~/.bashrc
    a) add line "PATH=$PATH:~/toolchains/$ARCH-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/usr/bin"
    b) exit from vi
source ~/.bashrc

2.8. Check installation:

# ARCH = sparc | arm | i686 | x86_64
$ARCH-linux-gcc --version
$ARCH-linux-gcc.br_real (Buildroot 2018.02.2) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

All done. Now you can use "gccprefix = $ARCH-linux-" in your project configuration file.

To re-build toolchain for other processor architecture do:

  1. make clean
  2. go to step 2.3.

Short script

1.  git clone git://git.buildroot.net/buildroot
2.  cd buildroot
3.  git checkout 2018.02.2
4.  sparcv8:  make qemu_sparc_ss10_defconfig
        arm:  make qemu_arm_vexpress_defconfig
        x86:  make qemu_x86_defconfig
     x86_64:  make qemu_x86_64_defconfig
5.  make menuconfig
    Build options --> libraries --> both static and shared
    Toolchain --> Enable WCHAR support
    Toolchain --> GCC compiler Version --> gcc 7.x
    Toolchain --> Enable C++ support --> on
    Toolchain --> Enable compiler link-time-optimization support --> on
    Toolchain --> Build cross gdb for the host --> on
    Target packages --> Libraries --> Other --> boost
    Target packages --> Libraries --> Other --> boost-filesystem
    Target packages --> Libraries --> Other --> boost-system
6.  make toolchain host-gdb boost
7.  # install
    sparcv8:  cp -r output/host/ ~/toolchains/sparc-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
    arm:      cp -r output/host/ ~/toolchains/arm-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
    x86:      cp -r output/host/ ~/toolchains/i686-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
    x86_64:   cp -r output/host/ ~/toolchains/x86_64-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
8.  # add to ~/.bashrc
    sparcv8:  PATH=~/toolchains/sparc-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/usr/bin:$PATH
    arm:      PATH=~/toolchains/arm-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/usr/bin:$PATH
    x86:      PATH=~/toolchains/i686-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/usr/bin:$PATH
    x86_64:   PATH=~/toolchains/x86_64-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/usr/bin:$PATH
9.  source ~/.bashrc

# NOTE:  to re-build toolchain for other processor architecture do:
#        a) make clean
#        b) go to step 4

3. Build libm from sources [up]


WrmOS kernel and system software (sigma0, alpha) works without libm. But if you require linking with libm, please read notes below.

Unfortunately latest versions of uClibc replace content of libm to libc. It is not usable for cross-compiling with WrmOS. To get separated libm need to build previous version of uClibc (buildroot 16.08.1 has uClibc version 1.0.17). Below you can findĀ  step-by-step manual how to download and build libm. This manual is common for all processor architectures. Differences are additional marked.

Step-by-step

3.1. Clone Buildroot git repository:

git clone git://git.buildroot.net/buildroot
cd buildroot

If you already have buildroot repository, please do:

make clean

3.2. Switch repository state to tag 2016.08.1:

git checkout 2016.08.1

3.3. Choose default configuration to based on it (this step is architecture depended):

SPARCv8:  make qemu_sparc_ss10_defconfig
ARM:      make qemu_arm_vexpress_defconfig
x86:      make qemu_x86_defconfig
x86_64:   make qemu_x86_64_defconfig

3.4. Start building (it may take a few minutes):

make toolchain

3.5. Copy result to installation directory (for example ~/toolchains/):

# ARCH = sparc | arm | i686 | x86_64
cp output/build/uclibc-1.0.17/lib/libm.a ~/toolchains/$ARCH-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/$ARCH_uclibc-1.0.17_libm.a
cd ~/toolchains/$ARCH-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
ln -s $ARCH_uclibc-1.0.17_libm.a libm.a
cd -

3.6. Using libm:

To specify libm inside WrmOS Makefile's use the next path:

$(shell $(gccprefix)gcc -print-sysroot)../../libm.a

To re-build libm for other processor architecture do:

  1. make clean
  2. go to step 3.3.

Short script

1.  git clone git://git.buildroot.net/buildroot
2.  cd buildroot
3.  git checkout 2016.08.1
4.  sparcv8:  make qemu_sparc_ss10_defconfig
        arm:  make qemu_arm_vexpress_defconfig
        x86:  make qemu_x86_defconfig
     x86_64:  make qemu_x86_64_defconfig
5.  make toolchain
6.  # install
    sparcv8:  cp output/build/uclibc-1.0.17/lib/libm.a ~/toolchains/sparc-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/sparc_uclibc-1.0.17_libm.a
              cd ~/toolchains/sparc-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
              ln -s sparc_uclibc-1.0.17_libm.a libm.a
              cd -
    arm:      cp output/build/uclibc-1.0.17/lib/libm.a ~/toolchains/arm-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/arm_uclibc-1.0.17_libm.a
              cd ~/toolchains/arm-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
              ln -s arm_uclibc-1.0.17_libm.a libm.a
              cd -
    x86:      cp output/build/uclibc-1.0.17/lib/libm.a ~/toolchains/i686-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/i686-uclibc-1.0.17_libm.a
              cd ~/toolchains/i686-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
              ln -s i686_uclibc-1.0.17_libm.a libm.a
              cd -
    x86_64:   cp output/build/uclibc-1.0.17/lib/libm.a ~/toolchains/x86_64-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0/x86_64_uclibc-1.0.17_libm.a
              cd ~/toolchains/x86_64-buildroot-linux-uclibc_br2018.02.2_gcc7.3.0
              ln -s x86_64_uclibc-1.0.17_libm.a libm.a
              cd -8.  # using in WrmOS Makefile's:
    $(shell $(gccprefix)gcc -print-sysroot)../../libm.a

# NOTE:  to re-build libm for other processor architecture do:
#        a) make clean
#        b) go to step 4