S3C2440-Bare Metal Edition-02 | Installing and using the arm-linux-gcc cross-compilation toolchain

Publisher:心灵清澈Latest update time:2021-07-30 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Why do we need cross-compilation tools?

The host machine runs a standard Linux operating system, but the compiled program needs to run on the target machine's Linux. This is called cross-compilation, and the compiler is called a cross-compiler.


We have used gcc to compile programs for the Linux local host before (Linux C language programming (Part 1) | Use of gcc), and the target system of the compiler we need now is ARM, which does not run an operating system but only runs bare metal programs. We need to compile a program on the Linux host that can run on the S3C2440@ARM920T chip, so we cannot use this compiler and need to use the arm-linux-gcc cross compiler.


2. Installation of arm-linux-gcc

arm-linux-gcc is the official arm compiler based on Linux platform, its features are:


Open source and free

Supports many ARM chips

Powerful and stable


2.1. Download arm-linux-gcc

Here I downloaded from a friendly website:

Download and upload the compressed package to the Linux host, as shown in the figure:


Unzip:


tar -zxvf arm-linux-gcc-4.4.3-20100728.tar.gz

Enter the directory /opt/FriendlyARM/toolschain and rename it:


mv 4.4.3/ arm-linux-toolchains4.4.3


Then move the directory to /usr:


sudo mv arm-linux-toolchains4.4.3/ /usr

Enter the directory and check that the tools we need are stored under bin:

2.2. Setting environment variables

Add the location where the tools are stored in the previous step to the user environment variable, use vim ~/.bashrc, and then add at the end:


export PATH=$PATH:/usr/arm-linux-toolchains4.4.3/bin

Then use the command source ~/.bashrc to update the system path so that the added environment variables take effect immediately:

Then enter arm-linux-, press tab, and check whether it can be automatically completed. If it can, the installation is successful:

Execute arm-linux-gcc and check the version, mainly to check whether the tool chain can run normally:

2.3. Add 32-bit library support (64-bit system)

If it is a 64-bit operating system, it cannot be used at this time. It can only be automatically completed but cannot be executed:

Solution - Install the library:


sudo apt-get install libc6-i386


After the installation is complete, check the gcc version again to see if it is successful:


3.Use of arm-linux-gcc

There is not much difference between arm-none-linux-gnueabi-gcc and the previous gcc. The example is as follows.

First edit the file hello.c:


#include


int main(void)

{

    printf("hello,world.n");

    return 0;

}


Then compile using the cross toolchain:

The compiler prompts that the library libstdc++.so.6 is missing. This is a problem of missing 32-bit libraries:


libstdc++6

lib32stdc++6

solution:


sudo apt-get install libstdc++6 

sudo apt-get install lib32stdc++6


After the installation is complete, compile again and the compilation is successful:

The compiler prompts that the library libstdz.so.1 is missing. Solution:


sudo apt-get install lib32z1


After the compilation is complete, you can download the generated executable file from the server, burn it to the target board and run it. Check the generated executable file type:

You can see that this is an executable program on a 32-bit ARM machine.


4. Linking of target files in embedded development

When using a cross-compilation toolchain, the most important process is the linking process:


Simple program links can be specified using a few parameters;

Complex program links need to be specified using the link file .ld.

Here we only explain the most necessary parameter: -Ttext 0. This parameter indicates that the program segment is stored starting from address 0 during linking, which corresponds to the program running starting from address 0 during execution.


5. Two arm-linux-tools commonly used in embedded development

5.1. Format conversion tool arm-linux-objcopy

The executable program compiled on the Linux host is usually in .out or .elf format, but the one we burn into the ARM chip is a .bin format file, so we need to use the format conversion tool arm-linux-objcopy. The conversion command is as follows:


arm-linux-objcopy -O binary -S led.elf led.bin


5.2. Disassembly tool arm-linux-objdump

In embedded development, most programs are written in C language. However, when encountering some problems, it is necessary to disassemble the executable program compiled by C language and troubleshoot errors according to the assembler. Use the tool arm-linux-objdump. The format is as follows:


arm-linux-objdump -D led.elf > led.dis


Note: All the above operations are written into a script and run with sudo:


tar -zxvf arm-linux-gcc-4.4.3-20100728.tar.gz

cd ./opt/FriendlyARM/toolschain

mv 4.4.3/ arm-linux-toolchains4.4.3

mv arm-linux-toolchains4.4.3/ /usr

sudo apt-get install libc6-i386

sudo apt-get install libstdc++6

sudo apt-get install lib32stdc++6

sudo apt-get install lib32z1



Keywords:S3C2440 Reference address:S3C2440-Bare Metal Edition-02 | Installing and using the arm-linux-gcc cross-compilation toolchain

Previous article:Exynos4412——SD card boot
Next article:14. Learn ARM-exynos4412-watchdog bare metal programming from scratch

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号