In this brief tutorial we shall discuss how to build and test a driver using UIO in Petalinux 2017.4

Building the HW:

To evaluate this flow, I have used the AXI GPIO in the Programmable Logic with the interrupt enabled, and connected to the PS IRQ:
bd.png
Generate the Output Products, Create HDL wrapper, Generate Bitstream and Export to SDK to create the HDF

Create the Linux Image in Petalinux:

Here, I used Petalinux 2017.4 to create the Image with the steps below:
  • petalinux-create -t project --template zynqMP -n linux_images
  • cd linux_images
  • petalinux-config --get-hw-description=<path to HDF>
  • petalinux-config -c kernel
    • Device Drivers -> Userspace I/O drivers
      • <*> Userspace I/O platform driver with generic IRQ handling
      • <*> Userspace platform driver with generic irq and dynamic memory
  • Open the system-user.dtsi in linux-images\project-spec\meta-user\recipes-bsp\device-tree\files and make the mods below:
/include/ "system-conf.dtsi"
/ {
    chosen {
        bootargs = "earlycon clk_ignore_unused   uio_pdrv_genirq.of_id=generic-uio";
        stdout-path = "serial0:115200n8";
    };
};
 
&axi_gpio_0 {
    compatible = "generic-uio";
};
 
  • petalinux-build
  • cd images/linux
  • petalinux-package --boot --fsbl zynqmp_fsbl.elf --fpga design_1_wrapper.bit --u-boot

Place the BOOT.BIN and the image.ub onto the SD card and boot the kernel.

Test the interrupts:

To test, make sure that the UIO is probed:
  • ls /dev
You should see that the uio0 is listed here.

Make sure that the IRQ is registered:
  • cat /proc/interrupts

You should see this registered as below:
interrupts_0.PNG
To generate an interrupt, we can write to the ISR in the AXI GPIO. Below is a snippet of the register space
from the AXI GPIO product guide
axi_gpio_reg.PNG
For example, we can use the devmem utility to write to this register from the linux console:

reg_write.PNG
Then rerun, the cat /proc/interrupts and the interrupt count should be incremented for the gpio:
interrupt_count.PNG

If users would like to debug a Linux application in SDK, then they can follow on from here with the wiki article here

Related Links