Adding Custom Modules - 2023.2 English

PetaLinux Tools Documentation: Reference Guide (UG1144)

Document ID
Release Date
2023.2 English
This section explains how to add custom kernel modules:
  1. Create a user module by running petalinux-create -t modules from inside a PetaLinux project on your workstation:
    cd <plnx-proj-root>
    petalinux-create -t modules --name <user-module-name> --enable

    For example, to create a user module called mymodule in C (the default):

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

    You can use -h or --help to see the usage of the petalinux-create -t modules. The new module recipe you created can be found in the <plnx-proj-root>/project-spec/meta-user/recipes-modules/mymodule directory.

    Note: If the module name has '_' or uppercase letters or starts with an uppercase letter, see Recipe Name has ' _ ' or Uppercase Letters or Starts with an Uppercase Letter.
  2. Change to the newly created module directory.

    cd <plnx-proj-root>/project-spec/meta-user/recipes-modules/mymodule

    You should see the following PetaLinux template-generated files:

    Table 1. Adding Custom Module Files
    Template Description
    Makefile Compilation file template - This is a basic Makefile containing targets to build and install your module into the root file system. This file needs to be modified when you add additional source code files to your project. Click here to customize the make file.
    README A file to introduce how to build the user module.
    mymodule.c Simple kernel module in C.
    <plnx-proj-root>/project- spec/meta-user/conf/user-rootfsconfig Configuration file template - This file controls the integration of your application/modules/libs into the PetaLinux RooFS menu configuration system. It also allows you to select or de-select the app and its dev, dbg packages into the target root file system.
  3. mymodule.c file can be edited or replaced with the real source code for your module. Later if you want to modify your custom user module, you are required to edit this file.
    Note: If you want to use the build artifacts for debugging with the third party utilities, add the following line in project-spec/meta-user/conf/petalinuxbsp.conf:
    RM_WORK_EXCLUDE += "mymodule"
Note: You can find all build artifacts under ${TMPDIR}/work/aarch64-xilinx-linux/mymodule/1.0-r0/.
Note: The modules created with petalinux-create -t modules have debug symbols by default.
You can delete the module directory if it is no longer required. Apart from deleting the module directory, you have to remove the line: CONFIG_mymodule from <plnx-proj-root>/project-spec/meta-user/conf/user-rootfsconfig. Deleting the directory by keeping the mentioned line in user-rootfsconfig throws an error.