petalinux中加入驱动模块

本文转载自:硬码农二毛哥微信公众号

注:本文由作者授权转发,如需转载请联系作者本人

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

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

  • 新建硬件平台,并到处xsa文件
  • 使用petalinux创建linux系统
  • 烧写sd卡,单板正常启动
  • Petalinux中添加驱动

    设置petalinux环境变量:

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

    进入petalinux工程目录:

    cd ~/eg3c/LC

    添加驱动命令

    petalinux-create -t modules --name hello

    运行后,生成recipes-modules文件夹

    进入recipes-modules文件夹,hello.c文件就是要添加的驱动,可以根据需要修改该文件。

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

    进入module模块,选中hello。

    重新编译
    petalinux-build

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

    运行应用程序
    vitis下创建应用程序

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

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

    tftp设置参考vitis下调试Linux应用程序。在编辑菜单设置虚拟机网络:

    运行指令:

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

    最新文章

    最新文章