Allwinner H616 cross-compilation, orangepi-zero2

What is cross compilation

Cross-compilation: refers to an executable file compiled on one platform and placed on another platform to run . For example, the 51 microcontroller uses keil programming. This is a cross-compilation. The .hex file generated after using keil compilation is then uploaded to On the stc89c51 microcontroller, we can run our 51 code .

Switching to Linux, if we gcc a file on the virtual machine, an .a.out file will be generated. We will put the .a.out file on the ARM-Linux platform for execution. This is cross-compilation of Linux. Why not directly Direct compilation for ARM-Linux platform? So much trouble?

Why do you need cross compilation?

1. Cost issue. Going to the company to develop is not as high as learning the ARM-Linux configuration. It is not enough to install the gcc compilation tool, or it cannot be compiled and run after it is installed. Resources are scarce, so cross-compilation was born . .

2. Does Raspberry Pi not need cross-compilation?
wrong. Want it too.
The Raspberry Pi is sometimes used because the target platform has not yet been established, and it does not even have an operating system, so it is impossible to talk about running any compiler. The operating system is also code and must be compiled!

The platform requires at least two things to run: bootloader (startup boot code) and operating system core

Host and target machines

Host : The platform for editing and compiling programs, usually an X86-based PC, also commonly called the host. (pc)
Target : A user-developed system, usually a non-X86 platform. The executable code compiled by the host is run on the target. (Allwinner, Raspberry Pi, etc.)

Tools required

Cross-compilation requires tools. For example, the 51 microcontroller requires keil software to be written. Note that the meaning of tools is to compile the host code into a tool that can run on the target and code.
Software download link:
Find gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz, which is the cross-compilation tool we need
Insert image description here
. Download it and get it on your own virtual machine.
I use shared memory to directly cp to the working directory.
Insert image description here

Decompression and compilation tools

tar -xvf  gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz

-x decompress
-v show progress
-f select file

Enter directory

cd gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/
cd bin

Insert image description here
The file marked in red aarch64-none-linux-gnu-gcc is the cross-compilation tool of Allwinner.

next

 pwd获得路径
echo $PATH 获得当前环境变量的值

Temporarily valid, configure environment variables (invalid when switching terminals)

PATH 环境变量
export PATH=$PATH$:{
    
    你pwm出来的路径}

Permanently valid, configure environment variables

Modify the .bashrc hidden file in the working directory and configure the command terminal

 vi /home/shunge/.bashrc 

Add to the last line of the file:

export PATH=$PATH$:{
    
    你pwm出来的路径}

Load the configuration file and the configuration will take effect immediately.

source /home/shunge/.bashrc

View version

aarch64-none-linux-gnu-gcc -v

Insert image description here

Done and start testing

Just write a demo
Insert image description here
and use the compilation tool to compile it.

 aarch64-none-linux-gnu-gcc demo1.c

Insert image description here
I found that after compiling on this machine, an error occurred when running the .a.out file. This is because the file has become an orangepi-compatible file and cannot be run on the PC.

cp demo1.c demo2.c	

Use two gccs to compile respectively, one is the system gcc, and the other is the one you just downloaded.
Insert image description here
Then proceed as follows:

aarch64-none-linux-gnu-gcc demo1.c -o quanzhi
gcc demo2.c -o pc

Insert image description here
Use the file command to check the difference between ordinary files.
Insert image description here
One is an x86-64 file and the other is an ARM file. Next, copy the quanzhi file into the orangepi-zero2 development board for testing.

Copy file test

Obtain the absolute path of orangepi-zero2 and prepare to put it in the test folder.
Insert image description here
Put this code on orangepi-zero2 and run it.

scp quanzhi orangepi@192.168.10.25:/home/orangepi/test
	 指令  文件名  开发板用户名@开发板地址:开发板的绝对路径

Insert image description here
Insert image description here

Transmission successful!

Prepare to execute
Insert image description here
and execute successfully!

Finish

If you encounter any problems, please feel free to ask for mutual progress!

Guess you like

Origin blog.csdn.net/qq_52749711/article/details/132306764