Xunwei 4412 development board experiment _Makefile compilation (on)

Introduction to this chapter In the tenth issue of the introductory video "Building a Compilation
Environment uboot_linux_Android ", it only introduced that the kernel can be compiled by entering the Make command, and did not introduce how it runs. When adding a driver to the kernel, three tasks need to be completed, including: 1) Add the new code in Kconfig corresponding to the compilation conditions of the project, which has been introduced in Experiment 3; 2) Add the driver source code to the corresponding directory , this step is easy to understand, and will be demonstrated in the experiment of this chapter; 3) Add the compilation entry for the new code in the file in the directory Makefile, which will be introduced in this chapter. 4.1.1 Tools 4.1.1.1 Hardware tools 1) PC 4.1.1.2 Software tools 1) Virtual machine Vmware 2) Ubuntu 12.04.2 3) Linux  source code generated by decompression under Ubuntu system  4.1.2 Preliminary course introductory video "01-burning" "Writing, Compiling and Basic Knowledge Video" → "Experiment 10 - Building the Compilation Environment uboot_linux_Android" or the manual "Five Android Development Environment Building and Compiling"; Experiment 3 Menuconfig_Kconfig 4.1.3 Video Resources This section's supporting video is "Video 04_Makefile Compilation" 4.2 Learning Objectives



















In this chapter you will learn the following:
Master the Linux kernel compilation commands
Master the method of setting the
compiler path Understand the relationship between the environment variable path, the compiler, and the compiler path in the source Makefile
Understand the structure
of the Makefile Master the method of adding script commands to the Makefile, you can see Understand Makefile Script
4.3 Compiler Path Setting
In the previous introductory knowledge, I only introduced in which directory to decompress the compiler and add the path to the environment variable file to compile the kernel, but did not introduce how they correspond.
As shown in the figure below, follow the basic tutorial provided above, configure the compiler and library files in Ubuntu, and enter the command "#make" to compile and generate the binary image of the kernel.

As shown in the figure below, use the command "#cd" and use the command "#vim .bashrc" to open the environment variable file ".bashrc".

As shown in the figure below, go to the bottom line and you can see that the compiler path is set to "exportPATH=$PATH:/usr/local/arm/arm-2009q3/bin" in the environment variable file.

Then use the command "#cd /usr/local/arm/" to enter the file directory of the decompressed compiler "arm-2009q3.tar.bz2".

It can be clearly seen that the path set in the environment variable corresponds to the decompression path.
Here go back to the directory of the kernel source code, as shown in the following figure.

As shown in the figure below, use the command "#vim Makefile" to open the Makefile in the kernel directory.

Here, find the parameter "CROSS_COMPILE" through the vim editor, as shown in the following figure.

The parameter "CROSS_COMPILE" can be found, as shown in the figure below.

As shown in the figure above, you can see that this parameter is "/usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-".
Looking at the next line of the parameter "CROSS_COMPILE", you can see that there are traces of modification here. It is easy to infer that Samsung used the "4.5.1" version of the compiler, but this does not matter, as long as it can be compiled and passed.
Generally speaking, the first step after getting the source code is to compile the source code first.
Set the variable "CROSS_COMPILE" in the above figure, the environment variable and the actual decompression path of the compiler to correspond. After these three correspond, it can be ensured that the system can find the compiler after executing the Make command.
During the execution of the compilation command, some errors will be prompted, and then according to the prompted errors, check and modify one by one, add library files or modify library files. This process can be long or short, and the test is only patience, and there is not much skill. Since the missing library files have been written into scripts, the following scripts can be compiled by executing the following scripts in the compiler.
For the Makefile file in the kernel directory, remind everyone that there is a lot of content in this file, and there is almost no need to pay attention to other parts except the compiler path variable above.
There is another place to know, as shown in the figure below, in the first line of the file, you can see the version of the kernel.

4.4 Introduction to the execution process of the Make kernel compilation command
As shown in the figure below, the make command needs to be executed to compile the kernel. After the make command is executed, it does not introduce how it is executed.

After the make command is executed, it will first find the "Makefile" file in the current directory, as shown in the following figure.

After running the Makefile, it will find the compiler's path "/usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-" in the Makefile as shown below.

Then the system finds the path of the "export PATH=$PATH:/usr/local/arm/arm-2009q3/bin" compiler according to the environment variable, as shown in the following figure.

As shown in the figure below, use the command "ls /usr/local/arm/arm-2009q3/bin/" to view the specific compilers after arm2009q3 is decompressed.

As shown in the figure above, after the system finds the compiler, the basic library files are also together with the compiler. Sometimes to compile a new kernel, it may be necessary to modify the library files.
Before compiling and executing, you also need to find the ".config" file, which is placed in the source directory by default. You can see it using the command "ls -a", as shown in the following figure.

From section 3.5 of 'Experiment 03' in this chapter, we learned that this ".config" is generated by the menuconfig tool, and there are only some macro definitions in it, as shown in the figure below, open this file.

Find the macro definition " LED S," which is the macro definition "LEDS_CTL" for compiling the led driver, as shown in the following figure.

Now the system finds this macro definition "LEDS_CTL", which will be used when compiling specific intermediate files.
How is it implemented? Continue to read the content of the next section to find out what the use of this macro definition is.

Related Posts