1.1.5. GCC ToolChain Setup

Before compiling any of the sources referenced in this document, set the cross compiler paths to the toolchains packaged in the Processor SDK [Recommended] as shown below. Refer to Yocto-built SDK Toolchains section for more details on usage.

host# export CROSS_COMPILE_64="${SDK_INSTALL_DIR}/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/aarch64-oe-linux/aarch64-oe-linux-"
host# export SYSROOT_64="${SDK_INSTALL_DIR}/linux-devkit/sysroots/aarch64-oe-linux"
host# export CC_64="${CROSS_COMPILE_64}gcc --sysroot=${SYSROOT_64}"
host# export CROSS_COMPILE_32="${SDK_INSTALL_DIR}/k3r5-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-oe-eabi/arm-oe-eabi-"

If the Processor SDK is not installed, the Arm GNU toolchains can be downloaded and setup. Refer to ARM toolchains section for more details on usage.

1.1.5.1. Yocto-built SDK Toolchains

The Processor SDK Linux AM62x package contains cross compile toolchains for the ARMv8 (linux-devkit) and ARMv7 (k3r5-devkit) architectures. These toolchains are used by the top level makefile when compiling the binaries for the target. These also package an environment setup script that, when sourced, sets all the right variables to compile binaries for the target architecture. The toolchain installers are built through the yocto build system, same as the target filesystem images themselves.

Below sections give some more details about the contents of these SDK Toolchains.

1.1.5.1.1. linux-devkit

Overview

The Processor SDK Linux AM62x package comes with this toolchain preinstalled at linux-devkit/ directory within the SDK. Below paths are relative to the <SDK_INSTALL_DIR> and will be referred to using the first column in the following sections.

Table 1.2 Linux Devkit Contents

Variable

Location

Description

CROSS_COMPILE_64

linux-devkit/sysroots/x86_64-arago-linux/usr/bin/aarch64-oe-linux/aarch64-oe-linux-

Cross compiler toolchain for the ARMv8 architecture

SYSROOT_64

linux-devkit/sysroots/aarch64-oe-linux/

Sysroot with the cross compiled libraries and headers for the ARMv8 architecture with Linux OS

ENV_SETUP_64

linux-devkit/environment-setup-aarch64-oe-linux

Shell script that sets environment variables to compile binaries for the ARMv8 linux target

Target Sysroot

The toolchain within the Linux SDK contains more than just the cross-compiler, it also contains pre-built libraries that can be used in your applications without requiring you to cross-compile them yourself. These libraries include packages from alsa to zlib. or a list of the libraries you can refer to the software manifest found in the <SDK INSTALL DIR>/manifest directory or look at the list of libraries available in the <SYSROOT_64>/usr/lib directory. You will also find the header files corresponding to these libraries in the <SYSROOT_64>/usr/include directory. As an example if your application wants access to the alsa asound library then you can now do the following command:

host# ${CROSS_COMPILE_64}gcc -lasound app.c -o app.out

Environment-setup script

When cross-compiling packages that use configuration tools and autotools there are many settings that are required to make sure that the proper cross-compile libraries are used. The environment-setup script located in the <SDK_INSTALL_DIR>/linux-devkit directory handles this for you. This script exports variables to perform actions such as:

  • Adding the toolchain to the PATH

  • Setting up CPATH

  • Setting up PKG_CONFIG_* paths

  • Setting standard variable such as CC, CPP, AR to the cross-compile values

To use the environment-setup script you only need to source it. This is as simple as:

host# source ${ENV_SETUP_64}

Note

Because environment-setup changes standard variables such as CC you should not use this script when compiler projects that build host-side as well as target-side tools. A prime example of this is the Linux kernel, which builds some host side tools to help during the kernel build. If the environment-setup script has been sourced then the CC value will specify the cross-compiler for the host-side tool build. This means that the tools compiled and used during the kernel build will be compiled for the ARM platform while the kernel build tries to run these tools on an Intel platform. This will cause the tools to fail to run and the kernel to fail to compile.

Example usage

In the simplest case the cross-compiler can be used to compile simple applications that just need access to standard libraries. The example below covers an application that uses only the standard libgcc libraries.

  1. First, create a helloworld.c file

    #include <stdio.h>
    
    int main() {
        printf ("Hello World from TI!!!\n");
        return 0;
    }
    
  2. Compile the c file to generate an executable for the target architecture, using one of the below 2 methods:

    • Compile Directly : Cross-compile the helloworld.c file using the cross-compile toolchain directly

      host# ${CROSS_COMPILE_64}gcc --sysroot=${SYSROOT_64} helloworld.c -o helloworld
      

      Be sure to give the correct path to the gcc cross compiler and target sysroot as listed earlier.

    • Using the environement setup script : Cross-compile after sourcing the setup script

      host# source ${ENV_SETUP_64}
      host# ${CC} helloworld.c -o helloworld
      
  3. After the above steps are run you should now have a helloworld executable in your directory that has been compiled for the ARM. A simple way to check this is to run the “file” command. It should return an output similar to below:

    host# file helloworld
    helloworld: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=bb96180ad71bd44e07fc148015a55c844134f30d, for GNU/Linux 3.14.0, with debug_info, not stripped
    

1.1.5.1.2. k3r5-devkit

Overview

The Processor SDK Linux AM62x package comes with an ARMv7 toolchain preinstalled at k3r5-devkit/ directory within the SDK. Below paths are relative to the <SDK_INSTALL_DIR>.

Table 1.3 k3r5 Devkit Contents

Variable

Location

Description

CROSS_COMPILE_32

k3r5-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-oe-eabi/arm-oe-eabi-

Cross compiler toolchain for the ARMv7 architecture

SYSROOT_32

k3r5-devkit/sysroots/armv7at2hf-vfp-oe-eabi/

Sysroot with the cross compiled libraries and headers for the ARMv7 architecture

ENV_SETUP_32

k3r5-devkit/environment-setup-armv7at2hf-vfp-oe-eabi

Shell script that sets environment variables to compile binaries for the target

1.1.5.2. ARM toolchains

It is strongly recommended to use the toolchain in the Processor SDK which is the version tested for TI platforms. In case the Processor SDK is not used, the toolchain can be downloaded and the toolchain path can be set as follows.

Arm Toolchain setup

Download the toolchain from here, and the version can be found in the release notes. The following example shows how to download and set toolchain paths into a <COMPILER_PATH> directory in Linux Host using x86_64 architecture. The environment variables defined here will be referenced in the build commands of the Foundational Components in this document.

host# COMPILER_PATH=/opt/arm-toolchain
host# mkdir -p $COMPILER_PATH
host# wget -c https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz -O - | tar -xv -J -C $COMPILER_PATH
host# wget -c https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz -O - | tar -xv -J -C $COMPILER_PATH
host# export CROSS_COMPILE_64=$COMPILER_PATH/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
host# export CROSS_COMPILE_32=$COMPILER_PATH/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-
host# export CC_64="${CROSS_COMPILE_64}gcc"