前文回顾
《Linux驱动开发(一)—环境搭建与hello world》
继续宣传一下韦老师的视频
70天30节Linux驱动开发快速入门系列课程【实战教学、技术讨论、直播答疑】
为了继续学习设备树的驱动开发,必须把这块功能在树莓派上弄清楚。
准备工作
开启ubuntu的ssh许可root用户登录,因为我这里的编译用的都是root权限。
安装vim,系统自带的vi是有问题的
apt install vim
重设root密码
sudo passwd root
修改ssh的配置
sudo vim /etc/ssh/sshd_config
修改两处
重启ssh服务
sudo service ssh restart
然后就可以通过winscp,登录root用户,进行文件传输拷贝了。
HelloWorld
入门自然helloworld,先试试能不能编译出模块。
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/module.h>
static int __init hello_init(void)
{
printk("hello world\n");
return 0;
}
static void __exit hello_exit(void)
{
printk("byebye world\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
hellowrold.c先放入linux/drivers/char下,然后修改该目录下Makefile
最后编译,命令是
ARCH