驱动编译调试主要有两种办法
1,安装linux-devel ,linux-headers,下载centos固件中源码进行编译
2,直接使用linux的内核源码进行新的编译。
1. 方法一
1.1. 安装内核和头文件依赖
Centos系统
|
Ubuntu系统
|
1.2. 下载内核源码
uname -r 查看内核版本信息
/cat /etc/*lease 查看文件系统信息
展开源码
Centos系统:Index of /
Linux SRC:https://vault.centos.org/7.8.2003/os/Source/SPackages/kernel-3.10.0-1127.el7.src.rpm 下载
1.3. 构建源码
以普通用户创建编译rpm所需的基础目录结构
|
安装编译内核所需软件包
|
安装内核源码
|
内核编译设置
|
拷贝当前内核的配置到源码目录,
直接复用当前内核的配置(避免重新编译整个内核,以及内核版本校验导致新模块加载错误的问题。)
|
1.4. 测试验证
|
hello/hello.c
展开源码
hello/Makefile
|
|
加载移除模块
|
1.5. 编译模块
|
2. 方法二
2.1. 下载内核源码
|
2.2. 准备编译环境
|
2.3. 编译
|
2.4. 设置默认启用内核
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编译内核 详细步骤_飙风的蜗牛博客-优快云博客_centos 内核编译
其它参考链接
[1] SystemTap on CentOS,https://sourceware.org/systemtap/wiki/SystemTapOnCentOS
[2] 我需要内核的源代码,https://wiki.centos.org/zh/HowTos/I_need_the_Kernel_Source
[3] 我需要创建一个自设的内核,https://wiki.centos.org/zh/HowTos/Custom_Kernel
[4] 创建你自己的内核模块,https://wiki.centos.org/zh/HowTos/BuildingKernelModules
[5] Building Source RPM as non-root under CentOS,http://www.owlriver.com/tips/non-root/