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
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 recipeblink.bb
.Change the C-file (driver file) and the Makefile as per your driver.
Take the LKM folder (reference files) and copy blink.c and blink.h into this directory.
Open the blink.bb recipe and add a
blink.h
entry inSRC_URI
.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
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.
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"
Next, we can beuild the Petalinux project
petalinux-build
Launch Vitis Unified IDE, and create a workspace.
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
- Create the Build Configurations
Right click anywhere in the Explorer View and select Edit Build Configurations
Below is an example of two build conifgurations; build and clean
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
To build, right click in ther Explorer view and select Build. Then select the Build configuration. This will create a blink.ko file
Use scp to copy the blink.ko onto the kernel, and insmod/rmmod to load and remove the module.