目录
第一个驱动hello world
把驱动编译成模块,然后加载到内核
开发板系统移植
把驱动编译到内核
配置vscode的内核头文件路径
编辑c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
//"${workspaceFolder}/**",
"I:/qqdownload/linux/linux-imx-rel_imx_4.1.15_2.1.0_ga/include",
"I:/qqdownload/linux/linux-imx-rel_imx_4.1.15_2.1.0_ga/include/uapi"
],
"defines": [
"__KERNEL__=1",
"KBUILD_MODNAME=\"mod_hello\"",
"MODULE=1"
]
}
],
"version": 4
}
settings.json里面
{
"files.associations": {
"init.h": "c",
"module.h": "c"
},
"C_Cpp.errorSquiggles": "Disabled"
}
hello.c
#include
#include
static int hello_init(void)
{
printk("hello world\n");
return 0;
}
static void hello_exit(void)
{
printk("bye bye\n");
}
module_init(hello_init); //加载模块(insmod helloworld.ko)时调用hello_init函数,
module_exit(hello_exit); //卸载模块(rmmod helloworld)时调用hello_exit函数
MODULE_LICENSE("GPL");
环境配置
cd 到内核源码路径
make menuconfig
export ARCH=arm
make menuconfig
编写Makefile
obj-m +=helloworld.o
KDIR:=/home/joyer/Documents/linux-imx-rel_imx_4.1.15_2.1.0_ga_20200903/linux-imx-rel_imx_4.1.15_2.1.0_ga
PWD?=$(shell pwd)
all:
make -C $(KDIR) M=$(PWD) modules
编译
编译内核
这个过程好像有点长,先配置好环境,然后运行create脚本。
问题汇总:Linux内核编译报错的解决办法 - 哎呀是不是疯啦 - 博客园
make menuconfig
export ARCH=arm
make menuconfig
在工程目录下
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
make
编译后:
运行
insmod helloworld.ko #加载驱动模块
rmmod helloworld #卸载驱动模块
1.按
【北京迅为】i.MX6ULL终结者开发板实操_哔哩哔哩_bilibili
烧录固件
2.同视频目录下安装编译器
3.同视频目录下安装nfs
#1. 安装 nfs 服务:
sudo apt-get install nfs-kernel-server
#2. 创建文件夹,存放开发板的根文件系统:
mkdir nfs_rootfs
chmod 777 nfs_rootfs
#3. 更改配置文件:
sudo vi /etc/exports
#文件末尾添加:
#/home/ubuntu/nfs_rootfs *(rw,sync,no_root_squash)
#前面路径修改为自己的路径,* 含义为所有的用户,*和后边的左括号"("之间不要出现空格
#rw:是可读写权限
#sync:是资料同步写入内存和硬盘
#no_root_squash:当登录NFS主机使用共享目录的使用者是root时,其权限将被转换成为匿名使用者,通常它的#UID与GID都会变成nobody身份。
#4. 重启 nfs 服务
sudo /etc/init.d/nfs-kernel-server restart
4.连接无线网,系统终端下:
wpa_passphrase XW "aaaaaaaa" >/etc/wpa_supplicant.conf
#命令中的“XW”是无线网络的名字,“aaaaaaaa”是无线网络的密码
wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wpa_supplicant.conf -dd >/var/wifi_log &
#使用 wpa_supplicant 命令链接 wifi 网络
udhcpc -i wlan0 &
#通过 dhcp 给 wlan0 分配 ip 地址
ifconfig
#虚拟机上装好nfs服务器后
ifconfug #查询虚拟机的网络地址
mount -t nfs -o nolock,nfsvers=3,vers=3 192.168.1.118:/home/joyer/nfs_rootfs /mnt
关于内核打印warnning 调整内核printk的打印级别_辛勤的摆渡人的博客-CSDN博客_调整内核打印级别
概念:
把驱动编译编译成模块,用M来表示
把驱动编译到内核里面,用*来表示
不编译。
路径
Makefile
obj-$(CONFIG_HELLO)+=helloworld.o
Kconfig
config HELLO
tristate "hello world"
help
hello hello
在的Kconfig
根目录下
编译寻找 下的imx_v7_defconfig
编译前
修改./configure
配置menuconfig
修改imx_v7_defconfig
配置编译环境
编译
问题
hello后加/
烧写镜像,验证。