第一步,创建项目
petalinux-create --type project --template zynq --name petalinux_Dma
petalinux-config --get-hw-description=.
第二步 指定SD和CMA,检查DMA
打开SD选项。
petalinux-config -c kernel
选择Image Packaging Configuration —>Root filesystem type(SD card) —>SD card
分离设备树
修改设备树后直接替换,默认是dtb会打包在uImage中。
Subsystem AUTO Hardware Settings -> Advanced boot… -> dtb image settings ->选择primary sd
保存kernel config小技巧
如果vivado工程中含有AXI-DMA 的IP核,在petalinux-config -c kernel的时候会发现基本相关项都已经开启。
这里用一个小技巧,我们在menuconfig中选保存,自己定一个保存名(例如alinx_sgdma_linux_defconfig),保存一下,不要退出,去你petalinux工程项目文件下搜索这个文件名,将其复制出来(我们之后为了编译模块也会用到它),按照github上的要求检查以下项目是否选y了(删除线的不需要检查,这个库是17年写的,但是现在xilinx的linux代码分支已经使用到2018,这些相关配置项已经不在了)
CONFIG_CMA=y
CONFIG_DMA_CMA=y
CONFIG_DMA_SHARED_BUFFER=y
记得,在menuconfig中再选保存,将文件名命名回.config,以供petalinux正确生成linux
DMA相关设置完毕后,我们还需要配置CMA
Device Drivers -> Generic Driver Options -> Default contiguous memory area size 的 Size in Mega Bytes修改为25
或者
第三步 添加DMA设备树
先运行一下生成pl相关的设备树(这是可选项,但有必要修改dtsi时直接拷贝pl.dtsi里的节点名,不容易出错)
$ petalinux-config -c device-tree
我们需要修改设备树的主要有两个点:1.加入axidma_chardev 2.修改各个dma通道的device-id不重复。
我这里有两个dma通道(一个发到FIFO,一个从FIFO接回来),我把他们的device-id分别修改为0和1
在project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi中加入
/include/ “system-conf.dtsi”
/{
};
&amba_pl{
axidma_chrdev: axidma_chrdev@0 {
compatible = “xlnx,axidma-chrdev”;
dmas = <&axi_dma_0 0 &axi_dma_0 1>;
dma-names = “tx_channel”, “rx_channel”;
};
};
下面这一段是大家网上普遍用的,但我用的有问题,我采用pl.dtsi文件里的设备树,只需要修改id为0和1
&axi_dma_0{
dma-channel@40400000 {
xlnx,device-id = <0x0>;
};
dma-channel@40400030 {
xlnx,device-id = <0x1>;
};
};
这里使用的设备树的引用覆盖的方法来修改device-id
第四步 添加axi_dma模块
*运行指令,创建xilinx-axidma module
john@john-virtual-machine:~/peta_proj/version2$ petalinux-create -t modules -n xilinx-axidma --enable
上面的命令可能产生两个效果,一是根文件系统中使能模块,二是添加镜像文件到下面文件petalinux-image-full.bbappend中
*创建完成后,可以在你的工程目录下找到如下路径/home/alinx/Downloads/peta_prj/dma_Show/project-spec/meta-user/recipes-modules/xilinx-axidma/files,进入这个路径,删除其中的xilinx-axidma.c文件。
*打开下载的模块文件包,将driver文件下的全部.c文件和.h头文件拷贝进files文件夹下,再将include文件夹下的axidma_ioctl.h文件也拷贝进来。*接下来,打开这个路径中的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
*修改xilinx-axidma.bb文件中,SRC_URI右侧的赋值为:
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
"
john@john-virtual-machine:~/peta_proj/version2$ petalinux-build -c xilinx-axidma
第五步 编译打包反向检查
petalinux-build
petalinux-package --boot --fsbl ./images/linux/zynq_fsbl.elf --fpga --u-boot --force
insmod xilinx_amidma.ko
这样在images目录下就会生成我们需要的uImage、system.dtb以及BOOT.BIN,为了确保设备树修改完好,我们这里先反编译一下设备树,生成system.dts,查看里面是否我们要修改的东西都已经修改好了(需要device-tree-compiler)。
在system.dtb文件的目录下运行
dtc -I dtb -O dts -o system.dts system.dtb
没用模块
(92条消息) ZYNQ #3 - Linux环境下在用户空间使用AXI-DMA进行传输_里先森-CSDN博客 https://blog.csdn.net/sements/article/details/90230188
用模块
(92条消息) Zynq7000学习 1.如何在Linux平台上运行DMA模块_江河湖海吾所望之的博客-CSDN博客 https://blog.csdn.net/weixin_38218267/article/details/102833570
(92条消息) 基于ZYNQ的petalinux 2017.4 DMA驱动的移植_七侠镇燕捕头的博客-CSDN博客 https://blog.csdn.net/qq_39337844/article/details/90238338
背景知识
Device Tree 中 address-cell 和 size-cells
m25p80@0 {
#address-cells=<1>
#size-cells=<1>;
partition@0 {
label = “u-boot”;
reg=<0x0 0x3000>
read-only;
}
我们可以看到m25p80这个父节点中的address-cells中填写了1,也就是,挂载在这个父节点下的子节点的起始地址只有1个;
size-cells中也填写了1,也就是挂载在这个父节点下的子节点的占用长度也只需要一个描述。
最后,我们看到就是
reg = <0 0x3000>;
0就是子节点绝对起始地址,个数1.
0x3000就是子节点占用长度,个数1.
(92条消息) 设备树中address-cells和size-cells的含义_violet089的专栏-CSDN博客 https://blog.csdn.net/violet089/article/details/53670758
#address-cells = <1>;
#size-cells = <1>;
...
serial@101f0000 {
compatible = "arm,pl011";
reg = <0x101f0000 0x1000 >;
};
serial@101f2000 {
compatible = "arm,pl011";
reg = <0x101f2000 0x1000 >;
};
gpio@101f3000 {
compatible = "arm,pl061";
reg = <0x101f3000 0x1000
0x101f4000 0x0010>;
};
每个设备都被分配了一个基址以及该区域的大小。这个例子中为 GPIO 分配了两个地址范围:0x101f3000…0x101f3fff 和 0x101f4000…0x101f400f。
————————————————
版权声明:本文为CSDN博主「躺着的树懒」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/violet089/article/details/53670758
#address-cells = <2>
#size-cells = <1>;
ethernet@0,0 {
compatible = "smc,smc91c111";
reg = <0 0 0x1000>;
};
外部总线的地址值使用了两个 cell,一个用于片选号;另一个则用于片选基址的偏移量。而长度字段则还是单个 cell,这是因为只有地址的偏移部分才需要一个范围量。所以,在这个例子中,每个 reg 项都有三个 cell:片选号、偏移量和长度。
————————————————
版权声明:本文为CSDN博主「躺着的树懒」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/violet089/article/details/53670758
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0xfec00000 0x180000>;
子地址空间的cell为1,因此0x0 0xfec00000 0x180000的第一个cell表示的是片选地址为0,第二个cell表示片选地址0的地址空间映射到CPU的地址空间为0xfec00000,第三个cell表示的是地址空间的大小。
#address-cells = <2>
#size-cells = <1>;
ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet
1 0 0x10160000 0x10000 // Chipselect 2, i2c controller
2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash
子地址空间的#address-cells为2,父地址空间的#address-cells值为1,因此0 0 0x10100000 0x10000的前2个cell为设备节点后片选0上偏移0,第3个cell表示设备节点后片选0上偏移0的地址空间被映射到CPU的0x10100000位置,第4个cell表示映射的大小为0x10000。ranges的后面2个项目的含义可以类推。
Android驱动之设备树简介 - 夜尽天明00 - 博客园 https://www.cnblogs.com/yejintianming00/p/9339754.html
(92条消息) 设备树的interrupts属性_a3121772305的博客-CSDN博客_interrupts https://blog.csdn.net/a3121772305/article/details/89500617
硬件配置
petalinux-config --get-hw-description=…/vivado
Device Drivers > Generic Driver Options > DMA Contiguous Memory Allocator > Size in Mega Bytes change the size from 16 to 256MB
Device Drivers -> Staging drivers -> Xilinx APF Accelerator driver
Device Drivers -> Staging drivers -> Xilinx APF Accelerator driver -> Xilinx APF DMA engines support
不是config, 为什么是conf
/project-spec/meta-user add in the following to the conf file.
CONFIG_xrt
CONFIG_xrt-dev
CONFIG_zocl
CONFIG_opencl-clhpp-dev
CONFIG_opencl-headers-dev
CONFIG_packagegroup-petalinux-opencv
/project-spec/meta-user/system-user.dsti.
&amba {
zyxclmm_drm {
compatible = “xlnx,zocl”;
status = “okay”;
};
};
大咖投稿 | Vitis培训课后感附详细技术解析(下) | 电子创新网赛灵思社区 http://xilinx.eetrend.com/content/2020/100049392.html
Once these have been implemented, we can configure the rootfs to include the user packages we have just defined.
petalinux-config -c rootfs
enabling the user packages
petalinux-package --boot --format BIN --fsbl images/linux/zynqmp_fsbl.elf --u-boot images/linux/u-boot.elf --pmufw images/linux/pmufw.elf --fpga images/linux/*.bit–force
$ petalinux-package --boot --fsbl --fpga --uboot
For detailed
2021。3。20再次记录
/project-spec/configs Configuration files of top level config and RootFS config
/project-spec/configs/config Configuration file used to store user settings
/project-spec/configs/rootfs_config Configuration file used for root file system.
/project-spec/meta-user/recipes-bsp/devicetree/files/system-user.dtsi is not modified by any PetaLinux tools.
/project-spec/meta-plnx-generated/recipesbsp/u-boot/configs U-Boot PetaLinux configuration files. The following files are auto generated by petalinux-config:
platform-auto.h config.cfg
platform-top.h will not be modified by any PetaLinux tools. When U-Boot builds, these files are copied into U-Boot build directory build/linux/u-boot/src/<U_BOOT_SRC>/ as follows:
config is the U-Boot kconfig file.
/components/ Directory for embedded software workspace and place to hold external sources while packing BSP. You can also
manually copy components into this directory. Here is the rule to place a external component: /components/ext_source/
/project-spec/meta-user/conf/petalinuxbsp.conf This configuration file contains all the local user configurations for your build environment. It is a substitute for “local.conf” in the Yocto meta layers.
kernel The following files are in /project-spec/meta-plnxgenerated/
recipes-kernel/linux/configs/
plnx_kernel.cfg
bsp.cfg
U-Boot The following files are in /project-spec/meta-plnxgenerated/
recipes-bsp/u-boot/configs/
config.cfg
platform-auto.h
/project-spec/meta-user/recipes-core/images/petalinux-user-image.bbappend
To remove any default feature, add the following code in the petalinuxbsp.conf:
IMAGE_FEATURES_remove = “ssh-server-dropbear”
To add any new feature, add the following command in the petalinuxbsp.conf:
IMAGE_FEATURES_append = " myfeature"
zynq plnx-zynq7
加bb
- The location of the recipe is /opt/pkg/petalinux/components/yocto/source/
aarch64/layers/meta-openembedded/meta-oe/recipes-benchmark/iperf3/
iperf3_3.2.bb.
加bb,还要加image,所以要加入petalinux-image-full.bbappend - Add the following line in /project-spec/meta-user/recipescore/
images/petalinux-image-full.bbappend.
IMAGE_INSTALL_append = " iperf3"
IMPORTANT! Whenever “_append” is used, there should be a space after = “.
加入petalinux-image-full.bbappend,不一定入根文件系统进行编译 - Run petalinux-config -c rootfs.
入了根文件系统 - Select user packages → iperf3. Enable it, save and exit.
编译文件 - Run petalinux-build.
创建模块
petalinux-create -t modules --name mymodule --enable
recipes-core/images/petalinux-image-full.bbappend
直接编译放到根文件里
petalinux-build -c rootfs
petalinux-build -x package
这显然把module归入root
Original: earlycon clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait
Updated: earlycon earlyprintk clk_ignore_unused root=/dev/mmcblk1p2 rw rootwait console=ttyPS0,115200
Edit the file “./project-spec/meta-user/conf/user-rootfsconfig” and add the following lines
CONFIG_xrt
CONFIG_xrt-dev
CONFIG_zocl
CONFIG_opencl-clhpp-dev
CONFIG_opencl-headers-dev
CONFIG_packagegroup-petalinux-opencv
&amba {
zyxclmm_drm {
compatible = “xlnx,zocl”;
status = “okay”;
reg = <0x0 0xA0000000 0x0 0x10000>;
};
petalinux-config -c rootfs
选择保存上面选项后的配置文件放在哪里
This includes changing the boot image, u-boot env partition, kernel image, and dtb image to ‘primary sd’ under Subsystem AUTO Hardware Settings > Advanced bootable images storage settings.
The root filesystem type needs to be changed to EXT (SD/eMMC/QSPI/SATA/USB)
petalinuxbsp.conf
- Copy or create a layer in <proj_root>/project-spec/meta-mylayer.
- Run petalinux-config → Yocto Settings → User Layers.
- Enter the following command:
${proot}/project-spec/meta-mylayer - Save and exit.
- Verify by viewing the file in <proj_root>/build/conf/bblayers.conf.
This can be added to /meta-user/recipes-core/packagegroups/
packagegroup-petalinux-alsa.bb.
To add this package group in RootFS menuconfig, add IMAGE_INSTALL_append = "
packagegroup-petalinux-alsa" in /project-spec/meta-user/
recipes-core/petalinux-image.bbappend to reflect in menuconfig.
Then launch petalinux-config -c rootfs, select user packages → packagegrouppetalinux-
alsa, save and exit. Then run petalinux-build.
原版本
CONFIG_CMA=y
CONFIG_DMA_CMA=y
CONFIG_XILINX_DMAENGINES=y
CONFIG_XILINX_AXIDMA=y
CONFIG_XILINX_AXIVDMA=y
CONFIG_DMA_SHARED_BUFFER=y
准备加
CONFIG_CMA=y
CONFIG_CMA_SIZE_MBYTES=25
CONFIG_CMA_SIZE_SEL_MBYTES=y
CONFIG_DMA_CMA=y
CONFIG_DMA_SHARED_BUFFER=y
│ Symbol: CMA_SIZE_MBYTES [=16] │
│ Type : integer │
│ Prompt: Size in Mega Bytes │
│ Location: │
│ -> Device Drivers │
│ -> Generic Driver Options
The kernel command line can be updated by changing the device tree or from the U-Boot console. For example, to set the CMA’s pool size to 25 MB from the U-Boot console:
setenv bootargs “${bootargs} cma=25M”
xilinx_axidma: loading out-of-tree module taints kernel.
axidma: axidma_of.c: axidma_parse_compatible_property: 50: Device tree node dma-channel: DMA channel lacks ‘compatible’ property.
axidma: axidma_dma.c: axidma_request_channels: 651: Unable to get slave channel 1: rx_channel.
axidma: probe of amba_pl:axidma_chrdev@0 failed with error -38
random: crng init done
A device tree entry for VDMA is generated automatically by the petalinux tools in
components/plnx_workspace/device-tree-generation/pl.dtsi, in my case:
/ {
amba_pl: amba_pl {
#address-cells = <1>;
#size-cells = <1>;
compatible = “simple-bus”;
ranges ;
axi_vdma_0: dma@43000000 {
#dma-cells = <1>;
clock-names = “s_axi_lite_aclk”, “m_axi_mm2s_aclk”, “m_axi_mm2s_aclk”, “m_axi_s2mm_aclk”, “m_axi_s2mm_aclk”;
clocks = <&clkc 15>, <&clkc 15>, <&clkc 15>, <&clkc 15>, <&clkc 15>;
compatible = “xlnx,axi-vdma-1.00.a”;
interrupt-parent = <&intc>;
interrupts = <0 29 4 0 30 4>;
reg = <0x43000000 0x10000>;
xlnx,addrwidth = <0x20>;
xlnx,flush-fsync = <0x1>;
xlnx,num-fstores = <0x3>;
dma-channel@43000000 {
compatible = “xlnx,axi-vdma-mm2s-channel”;
interrupts = <0 29 4>;
xlnx,datawidth = <0x20>;
xlnx,device-id = <0x0>;
xlnx,genlock-mode ;
};
dma-channel@43000030 {
compatible = “xlnx,axi-vdma-s2mm-channel”;
interrupts = <0 30 4>;
xlnx,datawidth = <0x20>;
xlnx,device-id = <0x0>;
xlnx,genlock-mode ;
};
};
};
};
The additonal manual device tree entry in project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
must contain only the chrdev device:
axidma_chrdev: axidma_chrdev@0 {
compatible = “xlnx,axidma-chrdev”;
dmas = <&axi_vdma_0 0 &axi_vdma_0 1>;
dma-names = “tx_channel”, “rx_channel”;
};
(Actually, there are some more entries for my platform here, but they are not related to DMA)
I followed the Instructions given above for creating the kernel module. I also have to include all
source files in xilinx-axidma.bb as described above, except for xilinx-axidma.c which is
deleted.
After building and booting the new system, I get the following on the target platform:
#dmesg |grep dma
[…]
xilinx-vdma 43000000.dma: Xilinx AXI VDMA Engine Driver Probed!!
使用"&“来引用“label”,即是引用phandle。property"cpu"通过”&cpu0"来对node"cpu@0":
Example 1: Build Device tree Only
The below example shows the steps to generate device-tree from PetaLinux project. The devicetree
recipe depends on HDF, native tools (dtc, python-yaml…), and kernel headers.
The setup commands are:
- Import HDF into work space:
petalinux-config --get-hw-description=<PATH-to-HDF/DSA-DIRECTORY>
Chapter 4: Configuring and Building
The above command will only copy hardware design from external location into the
petalinux project /project-spec/hw-description/. The
external-hdf is a recipe in Yocto which imports HDF from this location into Yocto work space.
All the HDF dependent recipes uses hardware design from Yocto workspace. By default, this
dependency is handled internal to recipes. You have to run the following command for every
update in hardware design if you are building without dependencies.
petalinux-build -c external-hdf - Prepare all the prerequisites (native utilities).
This command has to run only for the first time; re-run is needed only after cleaning
petalinux-build -c device-tree -x do_prepare_recipe_sysroot
Note: In future release, this feature is deprecated. Using petalinux-build -c <app/package/
component> -x for building individual task for a component as part of a petalinuxbuild
command will be deprecated. - Build the device tree ignoring dependency tasks using the following command:
petalinux-build -b device-tree
This command builds device tree ignoring all dependencies and deploys it in the images/
linux/ directory. If there is any dependency that is not met, it will error out. The above
command can be used for incremental builds as well.
Note: The above individual commands need to run with -b option. You can get all above functionality in
one run: petalinux-build -c device-tree. It will
&axi_dma_0 {
#dma-cells = <1>;
clock-names = “s_axi_lite_aclk”, “m_axi_mm2s_aclk”, “m_axi_s2mm_aclk”;
clocks = <&clkc 15>, <&clkc 15>, <&clkc 15>;
compatible = “xlnx,axi-dma-7.1”, “xlnx,axi-dma-1.00.a”;
interrupt-names = “mm2s_introut”, “s2mm_introut”;
interrupt-parent = <&intc>;
interrupts = <0 29 4 0 30 4>;
reg = <0x40400000 0x10000>;
xlnx,addrwidth = <0x20>;
xlnx,sg-length-width = <0xe>;
dma-channel@40400000 {
compatible = “xlnx,axi-dma-mm2s-channel”;
dma-channels = <0x1>;
interrupts = <0 29 4>;
xlnx,datawidth = <0x8>;
xlnx,device-id = <0x0>;
};
dma-channel@40400030 {
compatible = “xlnx,axi-dma-s2mm-channel”;
dma-channels = <0x1>;
interrupts = <0 30 4>;
xlnx,datawidth = <0x20>;
xlnx,device-id = <0x1>;
};
};
必须去掉dma@40400000,否则重复定义
axi_dma_0: dma@40400000 {
#dma-cells = <1>;
clock-names = “s_axi_lite_aclk”, “m_axi_mm2s_aclk”, “m_axi_s2mm_aclk”;
clocks = <&clkc 15>, <&clkc 15>, <&clkc 15>;
compatible = “xlnx,axi-dma-7.1”, “xlnx,axi-dma-1.00.a”;
interrupt-names = “mm2s_introut”, “s2mm_introut”;
interrupt-parent = <&intc>;
interrupts = <0 29 4 0 30 4>;
reg = <0x40400000 0x10000>;
xlnx,addrwidth = <0x20>;
xlnx,sg-length-width = <0xe>;
dma-channel@40400000 {
compatible = “xlnx,axi-dma-mm2s-channel”;
dma-channels = <0x1>;
interrupts = <0 29 4>;
xlnx,datawidth = <0x8>;
xlnx,device-id = <0x0>;
};
dma-channel@40400030 {
compatible = “xlnx,axi-dma-s2mm-channel”;
dma-channels = <0x1>;
interrupts = <0 30 4>;
xlnx,datawidth = <0x20>;
xlnx,device-id = <0x0>;
};
};
成功调入DMA模块