跳转到主要内容

petalinux中加入驱动模块

judy 提交于

本文转载自:<span id="profileBt"><a href="https://mp.weixin.qq.com/s/KeglSNH4a-wbpDJg4ml9ug">硬码农二毛哥微信公众号</a></spa…;

<font color="#FF8000">注:本文由作者授权转发,如需转载请联系作者本人</font>

使用petalinux定制完成Linux系统后,在单板中插入sd卡,系统正常启动。接下来要进行应用程序开发了,使用petalinux添加驱动是必须要经历的一个步骤。本文将介绍在petalinux添加驱动的步骤,展示应用程序调用后的效果。

<strong>准备工作</strong>
在petalinux中添加驱动前,需要完成如下工作:

<li>新建硬件平台,并到处xsa文件</li>
<li>使用petalinux创建linux系统</li>
<li>烧写sd卡,单板正常启动</li>

<strong>Petalinux中添加驱动</strong>

设置petalinux环境变量:

source /tools/Xilinx/PetaLinux/2021.1/settings.sh

进入petalinux工程目录:

cd ~/eg3c/LC

添加驱动命令

petalinux-create -t modules --name hello

运行后,生成recipes-modules文件夹
<center><img src="http://xilinx.eetrend.com/files/2022-09/%E5%8D%9A%E5%AE%A2/100564042-27…; alt=""></center>

进入recipes-modules文件夹,hello.c文件就是要添加的驱动,可以根据需要修改该文件。
<center><img src="http://xilinx.eetrend.com/files/2022-09/%E5%8D%9A%E5%AE%A2/100564042-27…; alt=""></center>

重新进入工程目录,运行
petalinux-config -c rootfs

<center><img src="http://xilinx.eetrend.com/files/2022-09/%E5%8D%9A%E5%AE%A2/100564042-27…; alt=""></center>

进入module模块,选中hello。
<center><img src="http://xilinx.eetrend.com/files/2022-09/%E5%8D%9A%E5%AE%A2/100564042-27…; alt=""></center>

重新编译
petalinux-build

在工程目录中搜索hello.ko,保存该文件。

<strong>运行应用程序</strong>
vitis下创建应用程序

具体工程参考博文Vitis下Linux应用程序开发流程。

将Debug文件夹xia的hellow.elf与之前生成的hello.ko文件通过tftp传输到单板。

tftp设置参考vitis下调试Linux应用程序。在编辑菜单设置虚拟机网络:
<center><img src="http://xilinx.eetrend.com/files/2022-09/%E5%8D%9A%E5%AE%A2/100564042-27…; alt=""></center>

运行指令:
<center><img src="http://xilinx.eetrend.com/files/2022-09/%E5%8D%9A%E5%AE%A2/100564042-27…; alt=""></center>

加载驱动,运行应用程序:
insmod hello.ko
./hellow.elf