Example 12: Device Driver Development - 2023.2 English

Zynq-7000 SoC Embedded Design Tutorial (UG1165)

Document ID
UG1165
Release Date
2024-05-02
Version
2023.2 English

You will use a Linux workstation for this example project. The device driver software is provided in the LKM folder of the ZIP file that accompanies this guide.

We will discuss two ways to create a Linux Module; using the Petalinux Utility and using Vitis Unified IDE.

Using Petalinux to Create the Module

  1. Under the PetaLinux project directory, use the command below to create your module:

    petalinux-create -t modules \--name mymodule \--enable
    

    PetaLinux creates the module in the <plnx-project>/project-spec/meta-user/ recipes-modules/ directory.

    For this exercise, create the “blink” module:

    petalinux-create -t modules \--name blink \--enable
    

    The default driver creation includes a Makefile, C-file, and README files. In this exercise, PetaLinux creates blink.c, a Makefile, and README files. It also contains the bit bake recipe blink.bb.

  2. Change the C-file (driver file) and the Makefile as per your driver.

  3. Take the LKM folder (reference files) and copy blink.c and blink.h into this directory.

  4. Open the blink.bb recipe and add a blink.h entry in SRC_URI.

  5. Run the command petalinux-build.

    After successful compilation the .ko file is created in the following location:

    <petalinux-build_directory>/build/tmp/sysroots-components/zc702_zynq7/blink/lib/modules/5.15.0-xilinx-v2022.2/extra/blink.ko
    
  6. You can install the driver using the modprobe command, which will be explained in further detail in the next section.

Using Vitis to Create the Module

The advatange of using Vitis to create a linux module is that the user can develop the code, deploy it on the target, evaluate and modify and re-deploy if needed.

  1. Users will need to provide the Vitis IDE with the linux-xlnx generated in Petalinux. By default, Petalinux will delete the intermittent binaries such as the linux-xlnx. Users will need to tell Petalinux to keep these files.

    To do this, users can open the petalinuxbsp.conf in project-spec/meta-user/conf and append the content below:

    RM_WORK_EXCLUDE += "linux-xlnx"
    
  2. Next, we can beuild the Petalinux project

    petalinux-build
    
  3. Launch Vitis Unified IDE, and create a workspace.

  4. Select User Managed Mode, and add all the files from LKM folder.

Note User Managed Mode is a new feature in Vitis Unified IDE that allows users to build makefile based applications without using the IDE

  1. Create the Build Configurations
    1. Right click anywhere in the Explorer View and select Edit Build Configurations

    2. Below is an example of two build conifgurations; build and clean

    ../_images/build_configurations.png

    Note: Users need to pass the KVERSION to the make file. This is the path to the linux-zynq_generic_7z020-standard-build in the petlainux project TMP_DIR. Users can get the TMP_DIR in petalinux-config

  2. To build, right click in ther Explorer view and select Build. Then select the Build configuration. This will create a blink.ko file

  3. Use scp to copy the blink.ko onto the kernel, and insmod/rmmod to load and remove the module.