目的:梳理ARM Linux驱动开发所需的环境和流程,记录遇到的问题。
环境介绍:
pc机:编写驱动程序和测试代码
服务器:编译驱动程序生成.ko文件,编译测试代码生成执行程序
单板:jz2440
准备工作:
linux内核:linux-2.6.22.6以及对应的补丁文件
工具链:gcc version 3.4.5
uboot:引导内核
uImage:引导根文件系统
根文件系统:运行应用程序
在进行驱动开发之前,单板上已经可以运行Linux系统,在搭建开发环境以及驱动开发的过程中,工具链的版本要保持一致。
为了方便将.ko文件和测试程序上传到单板的上,笔者采用NFS挂载目录的方式,简要总结一下步骤和遇到的问题。
1.服务器需要支持NFS挂载功能,如果不支持,需要手动下载:sudo apt install nfs-kernel-server
2.确定服务器支持NFS功能后,在/etc/exports中添加被挂载目录的路径:
/home/fitz/mount_bd *(rw,sync,no_subtree_check,no_root_squash)
3.重启nfs服务:sudo /etc/init.d/nfs-kernel-server restart
4.先尝试在服务器上挂载自身目录,测试nfs功能是否正常
mount -t nfs -o nolock ServerIP:目录 挂载的目录
5.在挂载服务器目录到单板linux系统之前,需要保证服务器和单板系统可以互相ping通。单板、主机、服务器有多种互联方式,强烈建议通过路由器或者交换机互联,最好不要pc通过无线上网,单板和pc通过网线直连。具体操作可参考韦东山老师视频。一句话总结:服务器上桥接的网卡与单板连接pc机的网卡要是同一网卡。
6.在单板的Linux上mount -t nfs -o nolock ServerIP:目录 挂载的目录即可挂载对应目录,以后将服务器上生成.ko和测试代码拷贝到该目录,就可以直接在单板系统上使用。
在实际使用的过程中会出现如下问题:
nfs: server 192.168.xx.xx not responding, still trying在加载驱动尤其是驱动比较大的时候会出现该问题。
原因:NFS默认的传输协议是UDP,而服务器和单板系统通过UDP交互时就会出现严重的网卡丢包现象。尤其是通过NFS复制较大文件的时候。
解决方案:
更改挂载命令
mount -t nfs -o nolock,rsize=4096,wsize=4096 ServerIP:目录 挂载的目录
至于背后更深层次的含义暂不作深究,问题得以解决即可。
至此,就可以开展ARM Linux驱动的开发工作了。