第二次写linux驱动总结

摘要:
第一个写驱动程序是在去年,也就是2019年10月左右。它是通过观看魏先生的视频一步一步完成的。出现了很多错误。建立环境需要付出很多努力。时间来到了2020年2月19日星期三,魏老师的新视频出来了。我跟着他再次学习。开发板是100ask_6ull,它仍然从设置环境开始,但我觉得这并不意味着进步,也不乏挫折。特别是,shinrk压缩虚拟机ubuntu的大小,导致其失败。幸运的是,它以前出口过一次

  第一次写驱动是在去年,2019年十月份左右。当时是看着韦老师的视频一步步完成的。其中经历了很多error.搭建环境花费了很多精力。时间来到了2020219日星期三,韦老师新视频出来了,我跟着再来了一次学习,使用开发板是100ask_6ull,依然是从搭建环境开始,不过感觉没有说明进步,该经历的坎坷,一样也没有少。特别是shinrk,压缩虚拟机ubuntu大小,导致挂掉,幸亏之前导出来过一次,又还原了!要不然,又要推迟2天!废话不多说,下面正式开始。

准备工作:

  1. 构建系统

使用如下命令一键配置/初始化开发环境,Wget是一种很好用的因特网下载工具,他具有的很多特性是其他工具所不能比拟的,再者他是一个轻量级可配置的下载工具。

命令:wget --no-check-certificate --tries=100 -c -O Configuring_ubuntu.sh https://dev.tencent.com/u/weidongshan/p/DevelopmentEnvConf/git/raw/master/Configuring_ubuntu.sh && sudo chmod +x Configuring_ubuntu.sh && sudo ./Configuring_ubuntu.sh

运行错误解决:

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)

此问题表明当前有某个进程正在apt-get,然而我并没有使用任何命令,于是需要kill掉进程。

解决方法是:

sudo rm /var/lib/apt/lists/lock

又出错了:

Err:70 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libdrm-amdgpu1 amd64 2.4.99-1ubuntu1~18.04.2

  Connection failed [IP: 91.189.91.24 80]

输入命令:sudo apt-get update

修改指令,增加: --tries=100 -c,意思是网络不好重复链接100次,-c表示续传。

再次执行上个指令。成功!

第二次写linux驱动总结第1张

2.获取imx6ull-sdk 源码

执行 7z x 100ask_imx6ull-sdk.7z.002 解压缩文件(解压缩时请不要用 sudo 命令,否则后面编译会有一些列错误发生)

第二次写linux驱动总结第2张

使用的是下载的文件!

100ask_imx6ull-sdk.7z.001

100ask_imx6ull-sdk.7z.002

这两个文件是一起的,不可缺少!

3.设置交叉编译工具链

交叉编译工具链用来在 ubuntu 主机上编译应用程序,而这些应用程序是在 ARM 等其他平台上运行。设置交叉编译工具主要是设置 PATHARCH CROSS_COMPILE 三个环境变量,下面介绍具体设置方法。

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabihf-

export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin

设置完毕后,要执行 source ~/.bashrc 命令使其生效。

  1. 编译

uboot

cd Uboot-2017.03

make distclean

make mx6ull_14x14_evk_defconfig

make

生成 u-boot-dtb.imx

⚫  编译内核

cd Linux-4.9.88

make mrproper

make 100ask_imx6ull_defconfig

make zImage

make dtbs

arch/arm/boot 目录下生成 zImage 内核文件, arch/arm/boot/dts 目录下生成

设备树的二进制文件 100ask_imx6ull-14x14.dtb

⚫  构建文件系统

 cd Buildroot_2019.02

make clean

make 100ask_imx6ull-qt_defconfig

make all

注意:因为后续要学习QT,所以不是100ask_imx6ull_qt_defconfig

5.烧录

  1. 上面步骤编译后的u-boot-dtb.imxzImage100ask_imx6ull-14x14.dtb 3个文件,copy到目录: 100ask_imx6ull-mfgtoolsProfilesLinuxOS Firmwarefiles 下。
  2. buildroot-image-100ask_100ask-ddr512m-emmc4g.vbs所在目录不要有中文!

USB线不要经过USB HUB!直接插到电脑!台式机不要插前面,插后面。

第二次写linux驱动总结第3张

点击buildroot-image-100ask_100ask-ddr512m-emmc4g.vbs烧录

 第二次写linux驱动总结第4张

 第二次写linux驱动总结第5张

上面准备工作做完了,下面就是进行驱动代码的编写和测试了。

  1. 怎么访问u盘,tf卡等,需要挂载

Mount -t

怎么查看有没有挂载?cat /proc/mounts查看。

  1. 怎么快速查看用户手册?

man 2 read

Man write

注意:黑科技,F,往前翻;B,往后翻。

3.怎么查找所用的函数比如printf()需要包含哪些头文件?

    就使用man指令查询,

  1. nfs配置

打开/etc/exports 文件,进行配置:

/work/        *(rw,nohide,insecure,no_subtree_check,async,no_root_squash)

/work/nfs_root 192.168.1.*(rw,nohide,insecure,no_subtree_check,async,no_root_squash)

使用以下语句刷新配置并且重启NFS

sudo exportfs -r

重启NFS服务

sudo /etc/init.d/nfs-kernel-server restart

在开发板上操作:

mount -o nolock -t nfs 192.168.1.9:/home/book/nfs_rootfs  /home/book/nfs_rootfs

  其中nfs 192.168.1.9:/home/book/nfs_rootfs是虚拟机的目录。

出现错误:Device or resource busy

改用命令:

mount -o nolock -t nfs 192.168.1.9:/home/book/nfs_rootfs  /mnt

  1. 驱动测试常用指令

insmod firstdrvtest.ko

chmod +x  firstdrvtest   //增加可执行属性,否则执行时会出现-

Lsmod

cat /proc/devices

ls /dev/hello -l

rmmod hello_drv //卸载驱动

dmesg  //查看printfk打印信息

代码具体过程就不贴出来了,有详细的教程,只记录下出现的问题的解决方法:

insmod lzhhello_drv..ko失败,见下方:

[root@imx6ull:/home/book/nfs_rootfs]# insmod lzhhello_drv.ko

[ 2231.161775] lzhhello_drv: loading out-of-tree module taints kernel.

[ 2231.169483] lzhhello_drv: disagrees about version of symbol device_create

[ 2231.179909] lzhhello_drv: Unknown symbol device_create (err -22)

[ 2231.193644] lzhhello_drv: disagrees about version of symbol device_destroy

[ 2231.206373] lzhhello_drv: Unknown symbol device_destroy (err -22)

[ 2231.215148] lzhhello_drv: disagrees about version of symbol device_create

[ 2231.223264] lzhhello_drv: Unknown symbol device_create (err -22)

[ 2231.230179] lzhhello_drv: disagrees about version of symbol device_destroy

[ 2231.237882] lzhhello_drv: Unknown symbol device_destroy (err -22)

insmod: can't insert 'lzhhello_drv.ko': Invalid argument

[root@imx6ull:/home/book/nfs_rootfs]

disagrees about version of symbol device_create Unknown symbol device_create

解决方法:

参考用户手册,更新内核

第二次写linux驱动总结第6张

实测OK

行如上操作后,重启开发板。并检查是否更新成功,方法是查看内核编译时间,对比下板子和虚拟机里ubuntu

◼  板子执行 cat /proc/version

◼  Ubuntu 虚拟机执行:date

对比内核编译的时间和当前运行内核的时间是不是一致,确保运行的内核更新最新的成

功。

要烧录的zlmage,以及dtb都在目录:/home/book/nfs_rootfs里面。

板子测试驱动记录如下:

[root@imx6ull:/home/book/nfs_rootfs]# rmmod hello_drv

[root@imx6ull:/home/book/nfs_rootfs]# lsmod

Module                  Size  Used by    Tainted: G

lzhhello_drv            3548  0

[root@imx6ull:/home/book/nfs_rootfs]# ./lzhhello_drv_test -w lzjdhsjcjsjj

can not open file /dev/hello

[root@imx6ull:/home/book/nfs_rootfs]# rmmod lzhhello_drv

[root@imx6ull:/home/book/nfs_rootfs]# lsmod

Module                  Size  Used by    Tainted: G

[root@imx6ull:/home/book/nfs_rootfs]# insmod lzhhello_drv.ko

以上就是本次学习的驱动部分记录,只选择主要的记录下来了。像makefile,代码编写过程等等都没有记录了,参考教程即可。

免责声明:文章转载自《第二次写linux驱动总结》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇QTP之下拉列表单选框…为CDH 5.7集群添加Kerberos身份验证及Sentry权限控制下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

不同linux禁用nouveau驱动方法

不同Linux系统nouveau驱动禁用方式 Fedora 创建文件/usr/lib/modprobe.d/blacklist-nouveau.conf,添加如下文本: blacklist nouveau options nouveau modeset=0 重新生成initramfs。 $ sudo dracut --force RHEL/Cent...

error while loading shared libraries: libhwloc.so.5: cannot open shared object file: No such file or directory

安装一个服务的时候碰到了这个问题: error while loading shared libraries: libhwloc.so.5: cannot open shared object file: No such file or directory 遇到了两次,一次是在Ubuntu 18系统上,一次是在Ubuntu 20系统上。 解决办法如下:...

linux springboot快捷启动脚本

yum install redhat-lsb -y   进入/usr/local/bin放入脚本springboot添加权限chmod +x springboot #################################### #!/bin/bash. /etc/profile if [ -r /lib/lsb/init-functions ];...

如何修改Linux系统的 /etc/ssh/sshd_config 文件 "/etc/ssh/sshd_config" E212: Can't open file for writin

第一步:我们使用命令行vim /etc/ssh/sshd_config   执行修改,强制保持  :wq!  系统不让我们修改这个文件 "/etc/ssh/sshd_config""/etc/ssh/sshd_config" E212: Can't open file for writingPress ENTER or type command to c...

Linux使用free命令buff/cache过高

在Linux系统中,我们经常用free命令来查看系统内存的使用状态。在一个RHEL6的系统上,free命令的显示内容大概是这样一个状态: 其实:buffers/cache占用的较多,说明系统中有进程曾经读写过文件,但是不要紧,这部分内存是当空闲来用的 Linux内核会在内存将要耗尽的时候,触发内存回收的工作,以便释放出内存给急需内存的进程使用。一般情况下...

记一次linux Microsoft Edge 白板 复原

恢复流程备份/home/make/.config/microsoft-edge-beta/删除/home/make/.config/microsoft-edge-beta/下的文件(非目录)。重新打开。ok 恢复了死机前的数据都在。 重新打开同步 就OK了 恢复过程中使用的其他方法改名 /home/make/.config/microsoft-edge-b...