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
Previous article:Exynos4412——SD card boot
Next article:14. Learn ARM-exynos4412-watchdog bare metal programming from scratch
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Water temperature sensor
- Infineon Position2Go Development Kit Review - skypinglee
- Schematic diagram of a quadrature oscillator
- Please tell me about the PB pin of GD32E230C
- Qorvo UWB Solution Receives Apple U1 Interoperability Certification
- Can't even see the taillights? LED makes car tail lighting safer
- EEWORLD University - How and why to replace discrete MOSFETs with load switches
- 【ESP32-C3-DevKitM-1】+ESP32 series universal Windows environment construction
- Digi-Key KOL video is here~ Senior algorithm engineer talks about the secrets of image processing
- 【RPi PICO】Run Fuzix system