0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

Petalinux2020.01 内核DMA驱动调试说明

C29F_xilinx_inc 来源:用户发布 作者:用户发布 2022-02-16 16:21 次阅读

1、在用户设备树中 pl-custom中

/delete-node/ &axi_dma_0;
/ {
axi_dma_0: dma@a0000000 {
#dma-cells = ;
clock-names = "s_axi_lite_aclk", "m_axi_mm2s_aclk", "m_axi_s2mm_aclk";
clocks = , , ;
compatible = "xlnx,axi-dma-7.1", "xlnx,axi-dma-1.00.a";
interrupt-names = "mm2s_introut", "s2mm_introut";
interrupt-parent = ;
interrupts = ;
reg = ;
xlnx,addrwidth = ;
xlnx,sg-length-width = ;
dma-channel@a0000000 {
compatible = "xlnx,axi-dma-mm2s-channel";
dma-channels = ;
interrupts = ;
xlnx,datawidth = ;
xlnx,device-id = ;
xlnx,include-dre ;
};
dma-channel@a0000030 {
compatible = "xlnx,axi-dma-s2mm-channel";
dma-channels = ;
interrupts = ;
xlnx,datawidth = ;
xlnx,device-id = ;
xlnx,include-dre ;
};
};
};

2 、在用户system-user中

/include/ "system-conf.dtsi"
/include/ "pl-custom.dtsi"
/ {
axidma_chrdev: axidma_chrdev@0 {
compatible = "xlnx,axidma-chrdev";
dmas = ;
dma-names = "tx_channel", "rx_channel";
};
};

&axi_dma_0 {
dma-coherent;
status = "okay";
};

3、device-tree.bbappend

SRC_URI += "file://system-user.dtsi"
SRC_URI += "file://pl-custom.dtsi"

4 、teminal

petalinux-create -t modules -n xilinx-axidma --enable

5 、github上下载dma驱动,xilinx_axidma-master.zip 并解压,由于内核的改变,对下列部分文件做出改变。
(1) makefile

DRIVER_NAME = xilinx-axidma
$(DRIVER_NAME)-objs = axi_dma.o axidma_chrdev.o axidma_dma.o axidma_of.o
obj-m := $(DRIVER_NAME).o

(2)xilinx-axidma.bb

SRC_URI = "file://Makefile \
file://axi_dma.c \
file://axidma_chrdev.c \
file://axidma_dma.c \
file://axidma_of.c \
file://axidma.h \
file://axidma_ioctl.h \
file://COPYING \

(3)axi_dma.c

#include
// new

(4)axidma_chrdev.c
linux 内核4.x到5.x,参数减少,查看内核函数,无影响
https://elixir.bootlin.com/linux/v4.9.251/source/include/linux/of_device.h
https://elixir.bootlin.com/linux/v4.9.251/source/include/linux/uaccess.h

在 static bool axidma_access_ok(const void __user *arg, size_t size, bool readonly)函数中

// if (!readonly && !access_ok(VERIFY_WRITE, arg, size)) {
if (!readonly && !access_ok(arg, size)) {

// } else if (!access_ok(VERIFY_READ, arg, size)) {
} else if (!access_ok(arg, size)) {

//of_dma_configure(struct device->dev, NULL);
of_dma_configure(struct device->dev, NULL,true);

(5)axidma_dma.c

#include
// new

static void axidma_dma_callback(void *data)
struct kernel_siginfo sig_info;

6、petalinux-build petalinux-build --sdk petalinux-package --sysroot

7、配置qt的环境。

8 qt 将example中的axidma_benchmark.c复制到qt,并添加其他所需文件。

(1)**.pro
SOURCES += \
gpio.cpp \
libaxidma.c \
main.cpp \
util.c

HEADERS += \
axidma_ioctl.h \
conversion.h \
gpio.h \
libaxidma.h \
util.h

(2)main.cpp() 由于是将C文件改为c++文件,所以此文件中这个函数需要做改变((void *)和(char *)相同)

static int single_transfer_test(axidma_dev_t dev, int tx_channel, void *tx_buf,
int tx_size, struct axidma_video_frame *tx_frame, int rx_channel,
void *rx_buf, int rx_size, struct axidma_video_frame *rx_frame)
{
int rc;

// Initialize the buffer region we're going to transmit
init_data((char *)tx_buf, (char *)rx_buf, tx_size, rx_size);

// Perform the DMA transaction
rc = axidma_twoway_transfer(dev, tx_channel, (char *)tx_buf, tx_size, tx_frame,
rx_channel, (char *)rx_buf, rx_size, rx_frame, true);
if (rc return rc;
}

// Verify that the data in the buffer changed
return verify_data((char *)tx_buf, (char *)rx_buf, tx_size, rx_size);
}

(3)在所有的 **.h中,为了使用QT的类功能,尽量用C++编程,对C文件的头文件做如下改变。

#ifdef __cplusplus
extern "C"{
#endif

......

#endif /* UTIL_H_ */

#ifdef __cplusplus
}
#endif

9、加载驱动

root@u3_save:/lib/modules/5.4.0-xilinx-v2020.1/extra# insmod xilinx-axidma.ko
[ 1637.846215] axidma: axidma_dma.c: axidma_dma_init: 725: DMA: Found 1 transmit channels and 1 receive channels.
[ 1637.856240] axidma: axidma_dma.c: axidma_dma_init: 727: VDMA: Found 0 transmit channels and 0 receive channels.

10、测试 因为dma的输入输出并没有还起来,所以只能看到发出去,看不到接收的

root@u3_save:/mnt# ./u3_dma_save
AXI DMA Benchmark Parameters:
Transmit Buffer Size: 7.91 MiB
R[ 1661.465441] axidma axidma: DMA mask not set
eceive Buffer Size: 7.91 MiB
Number of DMA Transfers: 1000 transfers

Using transmit channel 0 and receive channel 1.
[ 1671.710879] axidma: axidma_dma.c: axidma_start_transfer: 309: DMA receive transaction timed out.
[ 1672.719678] xilinx-vdma a0000000.dma: Cannot stop channel 00000000145aa465: 0
Failed to perform the AXI DMA read-write transfer: Timer expired

11、当使用环回时

root@u3_dma_test:/# ./mnt/u3_dma_save
AXI DMA Benchmark Parameters:
Transmit Buffer Size: 7.91 MiB
Receive Buffer Size: 7.91 MiB
Number of DMA Transfers: 1000 transfers

Using transmit channel 0 and receive channel 1.
Single transfer test successfully completed!
Beginning performance analysis of the DMA engine.

DMA Timing Statistics:
Elapsed Time: 41.49 s
Transmit Throughput: 190.66 MiB/s
Receive Throughput: 190.66 MiB/s
Total Throughput: 381.32 MiB/s
root@u3_dma_test:/#

13、qt and opencv 的配置
(1)安装sdk.sh
(2)在qt的pro中添加

INCLUDEPATH += /home/lcl/Soft/Sdk/sysroots/aarch64-xilinx-linux/usr/include

LIBS += \
-lopencv_imgcodecs \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_core \

即可。

14、接口改为128

root@u3_dma_test:/# ./mnt/u3_dma_save
AXI DMA Benchmark Parameters:
Transmit Buffer Size: 16.00 MiB
Receive Buffer Size: 16.00 MiB
Number of DMA Transfers: 1000 transfers

Using transmit channel 0 and receive channel 1.
Elapsed Time: 0.25 s
Single transfer test successfully completed!
Beginning performance analysis of the DMA engine.

DMA Timing Statistics:
Elapsed Time: 12.39 s
Transmit Throughput: 1291.32 MiB/s
Receive Throughput: 1291.32 MiB/s
Total Throughput: 2582.65 MiB/s
root@u3_dma_test:/#

15、第一个Elapsed Time: 0.25 s是当我把数据从缓冲区复制到其他位置消耗的时间,也就是16MB的数据需要250ms的时间,速率也就在60M左右,也验证以前的贴子,dma的实现方式(UIO或者内核驱动)与数据从缓冲区copy到别的地方的速率是没有关系的。

16、速度慢是缓冲区的问题 https://github.com/bperez77/xilinx_axidma/issues/69
(1)在设备树中
/include/ "system-conf.dtsi"
/include/ "pl-custom.dtsi"
/ {

axidma_chrdev: axidma_chrdev@0 {
compatible = "xlnx,axidma-chrdev";
dmas = ;
dma-names = "tx_channel", "rx_channel";
dma-coherent;
};
&axi_dma_0 {
dma-coherent;
status = "okay";
};

在测试代码中加速加入测速代码
......
rc = single_transfer_test(axidma_dev, tx_channel, tx_buf, tx_size,
tx_frame, rx_channel, rx_buf, rx_size, rx_frame);
if (rc goto free_rx_buf;
}

struct timeval start_time0, end_time0;
double elapsed_time0;
// Begin timing
gettimeofday(&start_time0, NULL);
memcpy(image_mid0, rx_buf, 2048*4096*4);
gettimeofday(&end_time0, NULL);
elapsed_time0 = TVAL_TO_SEC(end_time0) - TVAL_TO_SEC(start_time0);
printf("\tElapsed Time0: %0.2f s\n", elapsed_time0);

struct timeval start_time1, end_time1;
double elapsed_time1;
// Begin timing
gettimeofday(&start_time1, NULL);
memcpy(image_mid1, image_mid0, 2048*4096*4);
gettimeofday(&end_time1, NULL);
elapsed_time1 = TVAL_TO_SEC(end_time1) - TVAL_TO_SEC(start_time1);
printf("\tElapsed Time1: %0.2f s\n", elapsed_time1);

(3)测试结果
root@u3_dma_test:/# ./mnt/u3_dma_save
AXI DMA Benchmark Parameters:
Transmit Buffer Size: 32.00 MiB
[ 84.709677] axidma axidma: DMA mask not set
Receive Buffer Size: 32.00 MiB
Number of DMA Transfers: 1000 transfers

Using transmit channel 0 and receive channel 1.
Elapsed Time0: 0.07 s
Elapsed Time1: 0.07 s
Single transfer test successfully completed!
Beginning performance analysis of the DMA engine.

DMA Timing Statistics:
Elapsed Time: 24.75 s
Transmit Throughput: 1292.82 MiB/s
Receive Throughput: 1292.82 MiB/s
Total Throughput: 2585.64 MiB/s
root@u3_dma_test:/#

最后测得速率 32MB/70ms=450MB。
17、虽然速度是提高了,但是读写的数据是不对的
https://forums.xilinx.com/t5/%E5%B5%8C%E5%85%A5%E5%BC%8F-%E7%A1%AC%E4%BB...
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842098/Zynq+Ultr...

审核编辑:符乾江

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 驱动
    +关注

    关注

    11

    文章

    1718

    浏览量

    84357
  • Linux
    +关注

    关注

    87

    文章

    10992

    浏览量

    206744
收藏 人收藏

    评论

    相关推荐

    内核中的psci驱动是什么

    内核中的psci架构 内核psci软件架构包含psci驱动和每个cpu的cpu_ops回调函数实现两部分。 其中psci驱动实现了驱动初始化
    的头像 发表于 12-05 16:58 233次阅读
    <b class='flag-5'>内核</b>中的psci<b class='flag-5'>驱动</b>是什么

    zedboard petalinux构建工程错误是什么原因造成的?

    : do_ configure (log file is at / home/ yl/xlinx/petalinux/ hdmi_zed/building/tmp/work
    发表于 11-28 07:33

    内核调试工具printkprintk的输出格式

    很多内核开发者喜欢的调试工具是printk,在Linux内核中,使用printk()函数来打印信息,它与C库的printf()函数类似。 printk()与printf()的一个重要
    的头像 发表于 09-27 16:09 401次阅读

    PetaLinux工具文档:参考指南

    电子发烧友网站提供《PetaLinux工具文档:参考指南.pdf》资料免费下载
    发表于 09-15 11:48 0次下载
    <b class='flag-5'>PetaLinux</b>工具文档:参考指南

    PetaLinux工具文档

    电子发烧友网站提供《PetaLinux工具文档.pdf》资料免费下载
    发表于 09-15 10:43 0次下载
    <b class='flag-5'>PetaLinux</b>工具文档

    基于DWC_ether_qos的以太网驱动开发-收发驱动编写与调试

    本文转自公众号,欢迎关注 基于DWC_ether_qos的以太网驱动开发-收发驱动编写与调试 (qq.com) https://mp.weixin.qq.com
    的头像 发表于 09-05 08:47 1368次阅读
    基于DWC_ether_qos的以太网<b class='flag-5'>驱动</b>开发-收发<b class='flag-5'>驱动</b>编写与<b class='flag-5'>调试</b>

    Linux内核代码60%都是驱动

    为什么Linux内核代码60%都是驱动? 如果每支持新的设备就加入驱动内核会不会变得越来越臃肿?
    的头像 发表于 07-11 11:48 453次阅读
    Linux<b class='flag-5'>内核</b>代码60%都是<b class='flag-5'>驱动</b>?

    AMD Xilinx SoC:定制PetaLinux中的FSBL

    客户为AMD Xilinx SoC创建了PetaLinux工程。需要定制PetaLinux中的FSBL
    的头像 发表于 07-10 17:05 676次阅读

    使用PetaLinux 2019.2的Zynqberry Pi操作系统

    电子发烧友网站提供《使用PetaLinux 2019.2的Zynqberry Pi操作系统.zip》资料免费下载
    发表于 06-19 14:26 0次下载
    使用<b class='flag-5'>PetaLinux</b> 2019.2的Zynqberry Pi操作系统

    Linux内核学习笔记:printk调试

    很多内核开发者喜欢的调试工具是printk,在Linux内核中,使用printk()函数来打印信息,它与C库的printf()函数类似。
    发表于 06-01 15:14 637次阅读

    DMA通道关闭函数编译后无法调试的原因?怎么解决?

    DMA中断函数里添加了这段代码: dma_disable_channel(HPM_HDMA, 0); 后编译通过了,但是无法进入调试
    发表于 05-26 07:00

    Linux内核调试方式以及工具总结

    内核总是那么捉摸不透, 内核也会犯错, 但是调试却不能像用户空间程序那样, 为此内核开发者为我们提供了一系列的工具和系统来支持内核
    的头像 发表于 05-22 14:37 1156次阅读
    Linux<b class='flag-5'>内核</b><b class='flag-5'>调试</b>方式以及工具总结

    求助,为LPC55S69寻找带DMA的定时器驱动ADC示例

    我正在寻找一个示例来演示使用 DMA 设置定时器驱动的 ADC 转换以存储样本的正确方法。 所有提供的示例仅使用软件触发器。我不确定 DMA 示例试图完成什么 - 它说它使用“乒乓”模式来存储结果
    发表于 05-16 07:18

    Linux内核调试的方式以及工具汇总(下)

    内核总是那么捉摸不透, 内核也会犯错, 但是调试却不能像用户空间程序那样, 为此内核开发者为我们提供了一系列的工具和系统来支持内核
    的头像 发表于 05-12 14:59 961次阅读
    Linux<b class='flag-5'>内核</b><b class='flag-5'>调试</b>的方式以及工具汇总(下)

    Linux内核调试的方式以及工具汇总(上)

    内核总是那么捉摸不透, 内核也会犯错, 但是调试却不能像用户空间程序那样, 为此内核开发者为我们提供了一系列的工具和系统来支持内核
    的头像 发表于 05-12 14:58 679次阅读
    Linux<b class='flag-5'>内核</b><b class='flag-5'>调试</b>的方式以及工具汇总(上)