
petalinux-create -t project -n foo --template zynqMP
petalinux-config --get-hw-description=../ # DTG Settings >> (zcu102-rev1.0) MACHINE_NAME
petalinux-create -t modules --name u-dma-buf --enable
This create modules in ./project-spec/meta-user/recipes-modules/u-dma-buf/files where you can edit u-dma-buf.c as https://github.com/ikwzm/udmabuf/blob/master/u-dma-buf.c or u-dma-buf.c. You can check if u-dma-buf is available by running petalinux-config -c rootfs and see if it appears.
Then go to ./project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi and add two buffer to the device tree
/include/ "system-conf.dtsi"
/ {
udmabuf@0x00 {
compatible = "ikwzm,u-dma-buf";
device-name = "udmabuf0";
minor-number = <0>;
size = <0x4000000>;
sync-mode = <1>;
sync-always;
};
udmabuf@0x01 {
compatible = "ikwzm,u-dma-buf";
device-name = "udmabuf1";
minor-number = <1>;
size = <0x4000000>;
sync-mode = <1>;
sync-always;
};
};
petalinux-build
petalinux-boot --qemu --kernel --qemu-args "-boot mode=0"
Now you are in qemu which emulate the terminal of hardware. You can validate by
cd /sys/class/u-dma-buf
ls udma*
cd udmabuf0
cat phys_addr
Download https://github.com/bastibl/xilinx-dma as new project and create config at any workspace
cd ~
git clone <https://github.com/bastibl/xilinx-dma>
sudo apt install gcc-aarch64-linux-gnu
rustup target add aarch64-unknown-linux-gnu
Add this script to the file ~/.cargo/config.toml
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
Create the example in ~/xilinx-dma/examples/writedma.rs
use anyhow::Result;
use xilinx_dma::DmaBuffer;
fn main() -> Result<()> {
let buff = DmaBuffer::new("udmabuf0")?;
println!("{:?}", buff);
let data = buff.slice::<u32>();
for i in 0..8 {
data[i] = i as u32;
}
Ok(())
}