- 通过
WSL ubuntu
学习Linux
驱动开发; - 由于
WSL
和正式发布的Linux
使用的内核不一样,所以需要微软的内核源码; 通过uname -r
查看WSL
内核版本,然后在WSL2-Linux-Kernel下载相应版本的内核源码(不是最新版本)到本工程,并进行解压; - 源码配置:
sudo apt update
sudo apt install build-essential flex bison libssl-dev libelf-dev bc
cd ~/linux_driver/WSL2-Linux-Kernel-linux-msft-wsl-5.15.167.4
cp Microsoft/config-wsl .config
make oldconfig # 一直回车即可
make prepare
make scripts
make modules_prepare
hello
驱动编译:
cd ~/linux_driver/00_hello
make
ls -l hello.ko # check if the build is successful
sudo insmod hello.ko # install module
lsmod | grep hello
dmesg | tail
sudo rmmod hello
modinfo hello.ko
journalctl -f