Install GNU Arm Embedded Toolchain on Ubuntu 20.04

The GNU Arm Embedded toolchain is a collection of packages such as GCC (GNU Compiler Collection), Binutils, GDB, and other. It is used for embedded systems software development. This toolchain targets the 32-bit ARM Cortex-A, ARM Cortex-M, and ARN Cortex-R processor families.

This tutorial shows how to install GNU Arm Embedded toolchain on Ubuntu 20.04.

Install toolchain

There is no straightforward way to determine the latest version of toolchain via command line. So download web page and extract the latest version of toolchain as follows:

ARM_TOOLCHAIN_VERSION=$(curl -s https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads | grep -Po '<h3>Version \K.+(?= <span)')

Next, download archive file from official website:

curl -Lo gcc-arm-none-eabi.tar.bz2 "https://developer.arm.com/-/media/Files/downloads/gnu-rm/${ARM_TOOLCHAIN_VERSION}/gcc-arm-none-eabi-${ARM_TOOLCHAIN_VERSION}-x86_64-linux.tar.bz2"

Create a new directory to store toolchain files:

sudo mkdir /opt/gcc-arm-none-eabi

Extract toolchain files to specified directory:

sudo tar xf gcc-arm-none-eabi.tar.bz2 --strip-components=1 -C /opt/gcc-arm-none-eabi

Add /opt/gcc-arm-none-eabi/bin directory to the PATH environment variable.

echo 'export PATH=$PATH:/opt/gcc-arm-none-eabi/bin' | sudo tee -a /etc/profile.d/gcc-arm-none-eabi.sh

To make changes to take effect, logout and login to your system or run the following command to apply the changes immediately:

source /etc/profile

We can check version of compilers:

arm-none-eabi-gcc --version
arm-none-eabi-g++ --version

Remove unnecessary archive file:

rm -rf gcc-arm-none-eabi.tar.bz2

Testing toolchain

Create a main.c file:

nano main.c

Add the following code:

#include <stdio.h>

int main() {
    printf("Hello world\n");

    return 0;
}

Compile a code:

arm-none-eabi-gcc --specs=rdimon.specs main.c -o test

The file command can be used to verify that executable file is for ARM architecture.

file test

Output:

test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

Uninstall toolchain

If you want to completely remove GNU Arm Embedded toolchain, delete the installation directory:

sudo rm -rf /opt/gcc-arm-none-eabi

Remove gcc-arm-none-eabi.sh file that is used to set environment variable:

sudo rm -rf /etc/profile.d/gcc-arm-none-eabi.sh

Leave a Comment

Your email address will not be published.