Modules in Linux are pieces of code that can be loaded and unloaded into the kernel on demand. A piece of code that you add in this way is called a loadable kernel module (LKM). These modules extend the functionality of the kernel without the need to reboot the system. Without modules, you would need to build monolithic kernels and add new functionality directly into the kernel image. Besides having larger kernels, this has the disadvantage of requiring you to rebuild and reboot the kernel every time you want new functionality. > LKMs typically are one of the following things:
Device drivers: A device driver is designed for a specific piece of hardware. The kernel uses it to communicate with that piece of hardware without having to know any details of how the hardware works.
File system drivers: A file system driver interprets the contents of a file system as files and directories.
System calls: User space programs use system calls to get services from the kernel.
On Linux, each piece of hardware is represented by a file named as a device file, which provides the means to communicate with the hardware. Most hardware devices are used for output as well as input, so device files provide input/output control (ioctl) to send and receive data to and from hardware. Each device can have its own ioctl commands, which can be of the following types:
read ioctl: These commands send information from a process to the kernel.
write ioctl: These commands return information to a process.
Both read and write ioctl.
Neither read nor write ioctl.
For more details about LKM, refer to the Linux Kernel Module Programming Guide.
In this section you are going to develop a peripheral IP device driver as an LKM, which is dynamically loadable onto the running kernel. You must build the peripheral IP LKM as part of the same kernel build process that generates the base kernel image.
Note
If you do not want to compile the device driver, you can skip the example in this section and jump to Example 13: Loading a Module into a Kernel and Executing the Application. In that section, you can use the kernel image, which contains blink.ko
(image.ub
in the shared ZIP files). See Design Files for this Tutorial.
For kernel compilation and device driver development, you must use the Linux workstation. Before you start developing the device driver, the following steps are required:
Set the toolchain path in your Linux workstation.
Download the kernel source code and compile it. For downloading and compilation, refer to the steps mentioned in the AMD Zynq Linux Wiki Page.