ARM cross compiler gnueabi, gnueabihf and installation configuration, helloworld test

If we need to compile a helloworld program running on the X86 architecture, we only need to execute
gcc helloworld.c -o helloworld under the Linux system

If you want to compile a program running on an ARM system on an X86 host, you need to use a cross compiler.

1. Compiler naming rules:

The naming rule of the cross-compilation toolchain is: arch [-vendor] [-os] [-(gnu)eabi]

arch-architecture, such as ARM, MIPS
verdor-tool chain providers, such as Freescale provides tools referred to as fs
os-target operating system, such as linux
eabi-embedded application binary interface, Embedded Application Binary Interface (EABI)
according to the Whether the operating system is supported or not, ARM GCC can be divided into supported and unsupported operating systems, such as

arm-none-eabi: This does not have an operating system, and it is naturally impossible to support functions that are closely related to the operating system, such as fork(2). He uses newlib, a C library dedicated to embedded systems.

arm-none-linux-eabi: for Linux, use Glibc

2. Example:

1、arm-none-eabi-gcc
(ARM architecture,no vendor,not target an operating system,complies with the ARM EABI)

Used to compile ARM-based bare metal systems (including boot and kernel of ARM Linux, not suitable for compiling Linux applications),

Generally suitable for ARM7, Cortex-M and Cortex-R core chips, so it does not support those functions that are closely related to the operating system.

For example, fork(2), he uses newlib, a C library dedicated to embedded systems.

2、arm-none-linux-gnueabi-gcc
(ARM architecture, no vendor, creates binaries that run on the Linux operating system, and uses the GNU EABI)

It is mainly used for Linux systems based on ARM architecture, and can be used to compile u-boot, Linux kernel, Linux applications of ARM architecture, etc.

arm-none-linux-gnueabi is based on GCC, uses the Glibc library, and is a compiler optimized by Codesourcery.

The floating point calculations of arm-none-linux-gnueabi-xxx cross-compilation tools are excellent. Generally, ARM9, ARM11, Cortex-A kernels and Linux operating system will use them.

3. arm-eabi-gcc
Android ARM compiler.

4.
The compilation tool launched by armcc ARM has similar functions to arm-none-eabi and can compile bare metal programs (u-boot, kernel),

But you cannot compile Linux applications. Armcc generally works with ARM development tools. The compilers in Keil MDK, ADS, RVDS and DS-5 are all armcc, and most of the armcc compilers are charged.

5、arm-none-uclinuxeabi-gcc 和 arm-none-symbianelf-gcc

arm-none-uclinuxeabi is used for uCLinux, using Glibc.

arm-none-symbianelf is used for symbian.

3. ABI sum EABI:

ABI: Application Binary Interface (ABI) for the ARM Architecture. In the computer, the application binary interface describes the application (or other class

Type) and the low-level interface between the operating system or other applications.

EABI: Embedded ABI. The embedded application binary interface specifies the file format, data type, register usage, stack organization optimization, and standard conventions of parameters in an embedded software. Development

Users using their own assembly language can also use EABI as an interface with the assembly language generated by a compatible compiler.

The main difference between the two is that ABI is on the computer, and EABI is on the embedded platform (such as ARM, MIPS, etc.).

arm-linux-gnueabi-gcc 和 arm-linux-gnueabihf-gcc:

The two cross-compilers are applicable to two different architectures of armel and armhf respectively. The two architectures of armel and armhf adopt different strategies for floating-point operations.

(Arm with fpu can support these two floating-point arithmetic strategies).

In fact, these two cross-compilers are just different default values ​​of the gcc option -mfloat-abi. The gcc option -mfloat-abi has three values ​​soft, softfp, hard (the latter two are required

There is an fpu floating-point unit in arm, soft is compatible with the latter two, but the two modes of softfp and hard are not compatible with each other):

soft: Do not use fpu for floating point calculations, even if there is an FPU floating point arithmetic unit, do not use it, but use software mode.

softfp: The default value adopted by the armel architecture (corresponding compiler is arm-linux-gnueabi-gcc) is calculated by fpu, but the parameters are passed by ordinary registers, so that when interrupting, only ordinary registers need to be saved, and the interrupt load is small. But the parameters need to be converted to floating point and then calculated.

hard: Default armhf architecture (corresponding compiler arm-linux-gnueabihf-gcc) employed, the calculation fpu, transmission parameters are used in the floating point register fpu pass, eliminating the need for conversion, the best performance
is good, but the interrupt load high.

4. Installation and Configuration

First, take the compiler configuration of NXP's i.MX6Q platform as an example. The
official usually provides the following compressed package
gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar.gz.
First log in to the Ubuntu system and execute sudu su to enter Administrator rights, then you can create a folder yourself, or you can install the official recommended path to create a file plus.

mkdir  -p /opt/freescale/usr/local

Then unzip the toolkit

tar  zxvf  gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar.gz  -C  /opt/freescale/usr/local

Next, configure the PATH environment variable, the purpose is to use the cross compiler in any path.
One is to edit the profile file

vim  /etc/profile

Add at the end of the opened file

export ARCH=arm  

export CROSS_COMPILE=/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-none-linux-gnueabi- 

export PATH=/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin:$PATH 

Then press Esc to enter the command mode, then enter a colon, and enter wq after the colon to save and exit.

Another configuration method is

PATH=$PATH:/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin

Enter echo $PATH to check whether the PATH variable has been added successfully.

We can verify it by compiling helloworld.c.

Under the linux command line, execute vim helloworld.c and enter the following code.

#include"stdio.h" 

int main() 
	{
    
    
		 printf("HelloLinux!\n");
		 return 0; 
	}

If you execute
arm-none-linux-gnueabi-gcc helloworld.c -o helloworld_arm
, there is no prompt message. After executing the ls command, you can see an extra helloworld_arm file. After downloading to the ARM board,
execute chmod 777 helloworld_arm
and then ./helloword_arm
we can see that a line of Hellolinux is printed! success!

For the NXP LS1021A platform, because it is a cortex A7 architecture, the compiler needs to use another one.
This time we use network download to achieve.

sudo apt-get install gcc-arm-linux-gnueabifh

After ten minutes, execute

arm-linux-gnueabihf-gcc -v

A long list of information will be printed, indicating that the installation was successful.

carry on

arm-linux-gnueabihf-gcc hello.c -o hello1021

Download hello1021 to the target board of LS1021A,
execute chmod 777 hello1021
and then ./hello1021
we can see that a line of Hellolinux is printed! success!

Guess you like

Origin blog.csdn.net/malcolm_110/article/details/108252425