Understanding Embedded Linux Cross-Compilation Environment Setup

1. Introduction

In the previous article titled “How to Install a Linux Virtual Machine”, we explained the installation method for a Linux virtual machine.

To build an embedded Linux development environment, it is necessary to configure the cross-compilation environment within the Linux virtual machine. Therefore, this article will introduce the configuration method for the cross-compilation environment.

2. Concept of Cross-Compilation Environment

The so-called cross-compilation environment is a compilation environment built on the Linux host for compiling software that runs on an embedded target machine.

The configuration work of the cross-compilation environment mainly includes: configuring the path (PATH) for the cross-compilation toolchain, the cross-compilation toolchain (CROSS_COMPILE), and the target platform architecture (ARCH) environment variables.

Among them, the CROSS_COMPILE and ARCH variables are generally standard variables in the Makefile of software project engineering, serving as environment variables for the make program. The target platform architecture discussed in this article is ARM.

3. Choosing a Cross-Compilation Toolchain

The selection criteria for the cross-compilation toolchain include the host hardware architecture, target platform architecture, and the type of software program (bare-metal program or Linux program).

The ARM official website provides various types of cross-compilation toolchains, and the Arm GNU Toolchain Downloads can be found at the following URL:

https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

Currently, the latest cross-compilation toolchain is based on GCC 13.2.

The cross-compilation toolchain for an X86_64 host with a target platform architecture of AArch32 is as follows, where the arm-none-eabi cross-compilation toolchain is suitable for bare-metal programs, and the arm-none-linux-gnueabihf cross-compilation toolchain is suitable for Linux programs.

Understanding Embedded Linux Cross-Compilation Environment Setup

The cross-compilation toolchain for an X86_64 host with a target platform architecture of AArch64 is as follows, where the aarch64-none-elf cross-compilation toolchain is suitable for bare-metal programs, and the aarch64-none-linux-gnu cross-compilation toolchain is suitable for Linux programs.

Understanding Embedded Linux Cross-Compilation Environment Setup

This article takes the Linux virtual machine as X86_64 architecture, the target platform architecture as AArch64, and compiles Linux 6.2.8 as an example, choosing the above arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-linux-gnu as the cross-compilation toolchain.

4. Configuring the Cross-Compilation Environment

(1) Configuration Principles

For the most commonly used cross-compilation toolchain and target platform architecture, permanent configuration is done in the ~/.bashrc file; for less frequently used cross-compilation toolchains and target platform architectures, a temporary configuration method is adopted, which can be either single terminal configuration or one-time configuration.

(2) Permanent Configuration

At the end of the ~/.bashrc file, add the following environment variable configuration statements:

export PATH=$PATH: ~/arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-linux-gnu/bin/

export CROSS_COMPILE=aarch64-none-linux-gnu-

export ARCH=arm64

Then, execute source ~/.bashrc to make the above configuration effective.

After the above configuration is completed, when the Linux virtual machine is started again in the future, there is no need to reconfigure; you can generate the image file using the command make Image.

(3) Single Terminal Configuration

This method is only applicable to the current terminal interface.

After opening the terminal, execute the following environment variable configuration statements:

export PATH=$PATH: ~/arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-linux-gnu/bin/

export CROSS_COMPILE=aarch64-none-linux-gnu-

export ARCH=arm64

Then, you can generate the image file using the command make Image.

(4) One-time Compilation Configuration

This method embeds the environment variable configuration statements into the make command, suitable for one-time compilation.

make CROSS_COMPILE=~/arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- ARCH=arm64 Image

Understanding Embedded Linux Cross-Compilation Environment Setup

END

Source: Embedded System Development
Copyright belongs to the original author. If there is any infringement, please contact for deletion.
Recommended Reading
Zhi Hui Jun is making big moves again!
Principle of Automatic Baud Rate Recognition for STM32 Serial Port
After 7 years of coding, I encountered such a ridiculous bug for the first time!

→Follow to avoid getting lost←

Leave a Comment