Linux:嵌入式linux驱动开发
@
首个驱动hellodrv
3、如果下载不到,就自己编写,并编译驱动。
1、编写源码
2、编译模块
1、先写makefile,注意KDIR是开发板内核源码位置:
obj-m += hellodrv.o
KDIR := /home/book/100ask_imx6ull-qemu/linux-4.9.88
PWD ?= /home/book/test
all:
make -C $(KDIR) M=$(PWD) modules
2、编译驱动
编译条件:
a、内核源码一定要先编译通过;
b、编译驱动模块用的内核源码一定要和开发板上运行的内核镜像是同一套;
c、看一下ubuntu环境是否是arm,make menucinfig
查看,export ARCH=arm
更改;
3、加载驱动
生成.ko文件,就是驱动
1、连接开发板
2、将.ko拷贝到开发板/mnt
3、insmod hellodrv.ko
4、lsmod
查看已加载的驱动模块
5、卸载模块rmmod hellodrv
,(没有.ko后缀)
2、命令行设置:
备份原配置文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
编辑源列表文件,命令如下:
sudo gedit /etc/apt/sources.list
将原有的内容删除掉,添加以下内容(不能有除了以下内容的有效内容)
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
更新软件列表
sudo apt-get update
更新软件包
sudo apt-get upgrade