How to compile the Linux kernel?

Online class: https://www.100ask.net/index (course viewing)
Forum: http://bbs.100ask.net/ (Academic Q&A)
Development Board: https://100ask.taobao.com/ (Taobao)
     https://weidongshan.tmall.com/ (
Tmall ) Exchange Group 1: QQ Group: 869222007 (Hongmeng Development/Linux/Embedded/Driver/Data Download)
Exchange Group 2: QQ Group: 536785813 (SCM-Embedded)
Public number: Baiwen Technology


version date Author Description
V1 2020 Wei Dongshan Excerpt from "Embedded Linux Application Development Complete Manual"

1. Introduction to Linux Kernel

Linux kernel (English: Linux kernel) is an open source Unix-like operating system macro kernel. The entire Linux operating system family is
deployed based on this kernel on traditional computer platforms (such as personal computers and servers in the form of Linux distributions) and various embedded platforms, such as routers, wireless access points, private branch exchanges, set-top boxes, FTA receivers Devices, smart TVs, digital video recorders, network attached storage (NAS), etc. The Android operating system that works on tablets, smart phones and smart watches, its underlying operating system is also Linux. Although the occupancy rate of desktop computers is relatively low, Linux-based operating systems dominate almost everything from mobile devices to mainframes. The actual Linux distribution Ubuntu, its ease of use is gradually approaching Windows.

Linux kernel official website: https://www.kernel.org/
linux Kernel Wikipedia: https://www.wiki.kernel.org/
read Linux kernel source code online: https://elixir.bootlin.com/
ST official source code Address: https://github.com/STMicroelectronics/linux.git
ST officially provides kernel source code examples: https://github.com/STMicroelectronics/linux-examples
100ask_Stm32mp157 development board Git warehouse address: https://gitee.com/ weidongshan/stm32mp15xc-kernel.git For
more information about the Linux kernel, please refer to the page: http://wiki.100ask.org/Category:Linux_Operating_System

The above Git repository is a Linux kernel specially formulated for the 100ask_imx6ull series development board, and it has the following features:
Insert picture description here

2. Compile the kernel image

Different development boards correspond to different configuration files, which are located in the kernel source arch/arm/configs/ directory.
The development environment such as the tool chain must be configured before compiling Linuxkernel. The cross-compilation tool chain we use here is Buildroot GCC 8.4.

Set up cross compilation and execute the compilation command.

book@100ask:~$ export ARCH=arm
book@100ask:~$ export CROSS_COMPILE=arm-buildroot-linux-gnueabihf-
book@100ask:~$ export PATH=$PATH:/home/book/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin


The compilation process of the STM32MP157 full-featured kernel is as follows (you need to configure some environment variables such as the tool chain before compiling the kernel):

book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ make 100ask_stm32mp157_pro_defconfig
book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ make uImage LOADADDR=0xC2000040 
book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ make dtbs

The compilation steps are as follows, the device tree file can be compiled after uImage is compiled. If you think the compilation speed is very slow, you can add -j<number> to use parallel task compilation, as shown below, add -j8 parameter to use 8 parallel tasks to compile the kernel , Compiling speed depends on performance, i7 9700F clocked at 3Ghz quad-core 8G memory full speed compilation may take about 5 minutes.
Insert picture description here
Insert picture description here
After the compilation is complete, the generated file is shown in the following figure. After the
Insert picture description here
compilation is completed, the uImage kernel file is generated in the arch/arm/boot directory, and the device tree
binary file stm32mp157c-100ask-512d-lcd is generated in the arch/arm/boot/dts directory -v1.dtb.
Copy these two files to the /home/book/nfs_rootfs directory for backup, as shown below:

book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ cp arch/arm/boot/uImage ~/nfs_rootfs/
book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ cp arch/arm/boot/dts/stm32mp157c-100ask-512d-v1.dtb ~/nfs_rootfs/

Insert picture description here

3. Compile the kernel module

No matter which version of the STM32MP157 development board, the command to compile the kernel module is the same.

STM32MP157 full-featured version After
entering the kernel source directory, you can compile the kernel module:

book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ make ARCH=arm CROSS_COMPILE=arm-buildroot-linux-gnueabihf- modules -j8

Screenshot example of kernel module compilation command execution
Insert picture description here

4. Install the kernel module to a directory in Ubuntu for use

You can first install the kernel module to the nfs root file system (/home/book/nfs_rootfs is the installation directory).
Note: The tree command will be executed below. If there is no such command, you need to execute the "sudo apt install tree" command to install the tree
tool (provided that Ubuntu can access the Internet).

STM32MP157 full-featured version
execute the following command:

book@100ask:~/100ask_stm32mp157_pro-sdk/Linux-5.4$ make ARCH=arm INSTALL_MOD_PATH=/home/book/nfs_rootfs modules_install

As shown in the figure below, install the module in the directory /home/book/nfs_rootfs/ where nfs is located: the
Insert picture description here
directory structure of /home/book/nfs_rootfs/
Insert picture description here
after installation is shown in the figure below: two links will be automatically generated after the module is compiled and installed To the link file of the kernel source directory, you need to manually delete these two link
files before you can continue to copy the kernel module to the development board, otherwise it will prompt problems such as insufficient space, as shown below, execute rm build source to delete the two red boxes Link file shown.

book@virtual-machine:~/nfs_rootfs/lib/modules/5.4.31-g04363cb64$ rm build source

Insert picture description here
After that, you can continue to copy the module to the development board.

Guess you like

Origin blog.csdn.net/thisway_diy/article/details/110077645