There are two main ways to compile and debug the driver
1. Install linux-devel, linux-headers, download the source code in the centos firmware to compile
2. Directly use the linux kernel source code for new compilation.
1. Method 1
1.1. Install the kernel and header file dependencies
CentOS system
|
Ubuntu system
|
1.2. Download the kernel source code
uname -r View kernel version information
/cat /etc/*lease View file system information
Expand the source code
Centos system: Index of /
Linux SRC: https://vault.centos.org/7.8.2003/os/Source/SPackages/kernel-3.10.0-1127.el7.src.rpm download
1.3. Building the source code
Create the basic directory structure required to compile rpm as a normal user
|
Install the packages required to compile the kernel
|
Install the kernel source
|
Kernel compilation settings
|
Copy the configuration of the current kernel to the source code directory,
Directly reuse the configuration of the current kernel (avoid recompiling the entire kernel, and the problem of kernel version verification causing new module loading errors.)
|
1.4. Test verification
|
hello/hello.c
Expand the source code
hello/Makefile
|
|
load remove module
|
1.5. Compile the module
|
Reference link: CentOS7 compiles its own kernel module - short book
2. Method 2
2.1. Download the kernel source code
|
2.2. Prepare the compilation environment
|
2.3. Compile
|
2.4. Set default enable kernel
awk -F\' '$1=="menuentry " {print i++ " : " $2}' $(find /boot -name grub.cfg)
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (4.4.241.test.x86_64+) 7 (Core)
1 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)
4 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
5 : CentOS Linux (0-rescue-f6b59b458a184fd3a3bc8bed678e1a52) 7 (Core)
grub2-set-default 1
grub2-editenv list
cat /etc/default/grub
|
三,配置内核启动项
GRUB配置: GRUB_CMDLINE_LINUX="intel_iommu=on iommu=pt"
awk -F\' '$1=="menuentry " {print i++ " : " $2}' $(find /boot -name grub.cfg)
0 : CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-f6b59b458a184fd3a3bc8bed678e1a52) 7 (Core)
grub2-set-default 1
grub2-editenv list
cat /etc/default/grub
" http://vault.centos.org"去下载内核源码。https://vault.centos.org/7.8.2003/正在上传…重新上传取消
下载地址:Index of /7.8.2003/updates/Source/SPackages
找到当前内核版本
内核源码安装参考: CentOS安装相应版本的内核源码 - AlexAlex - 博客园
模块编译参考: CentOS7编译自己的内核模块 - 简书
yum install kernel-headers kernel-devel
内核编译:
cd /root/rpmbuild/BUILD/kernel-3.10.0-1160.25.1.el7/linux-3.10.0-1160.25.1.el7.x86_64
$ make M=modules/hello
$ sudo cp modules/hello/hello.ko /lib/modules/`uname -r`/extra
$ cd /lib/modules/`uname -r`/extra
$ sudo insmod hello.ko
$ sudo rmmod hello
$ tail -f /var/log/messages
参考链接
CentOS7编译内核 详细步骤_飙风的蜗牛博客-CSDN博客_centos 内核编译
其它参考链接
[1] SystemTap on CentOS, https://sourceware.org/systemtap/wiki/SystemTapOnCentOS
[2] I need the source code of the kernel, https://wiki.centos.org/zh/HowTos/I_need_the_Kernel_Source
[3] I need Create a custom kernel, https://wiki.centos.org/zh/HowTos/Custom_Kernel
[4] Create your own kernel modules, https://wiki.centos.org/zh/HowTos/BuildingKernelModules
[5] Building Source RPM as non-root under CentOS, http://www.owlriver.com/tips/non-root/