Devices and Modules
Four kernel components related to device drivers and device management:
Device typesClassifications used in all Unix systems to unify behavior of common
devices ModulesThe mechanism by which the Linux kernel can load and unload object code on demand Kernel objectsSupport for adding simple object-oriented behavior and a parent/ child relationship to kernel data structures SysfsA filesystem representation of the systems device tree
n
Device Types In Linux, as with all Unix systems, devices are classified into one of three types: Block devices Character devices Network devices
Often abbreviated blkdevs, block devices are addressable in device-specified chunks called blocks and generally support seeking, the random access of data. Example block devices include hard drives, Blu-ray discs, and memory devices such as flash. Block devices are accessed via a special file called a block device node and generally mounted as a filesystem. Often abbreviated cdevs, character devices are generally not addressable, providing access to data only as a stream, generally of characters (bytes). Example character devices include keyboards, mice, printers, and most pseudo-devices. Character devices are
accessed via a special file called a character device node. Unlike with block devices, applications interact with character devices directly through their device node. Sometimes called Ethernet devices after the most common type of network devices, network devices provide access to a network (such as the Internet) via a physical adapter (such as your laptops 802.11 card) and a specific protocol (such as IP). Breaking Unixs everything is a file design principle, network devices are not accessed via a device node but with a special interface called the socket API. Linux provides a handful of other device types, but they are specialized to a single task and not common. One exception is miscellaneous devices, often abbreviated miscdevs, which are actually a simplified form of character devices. Miscellaneous devices enable a device driver author to represent simple devices easily, trading functionality for common infrastructure.
Modules
Despite being monolithic, in the sense that the whole kernel runs in a single address space, the Linux kernel is modular, supporting the dynamic insertion and removal of code from itself at runtime. Related subroutines, data, and entry and exit points are grouped together in a single binary
image, a loadable kernel object, called a module. Support for modules allows systems to have only a minimal base kernel image, with optional features and drivers supplied via loadable, separate objects. removal and reloading of kernel code, facilitate debugging, and allow for the loading of new drivers on demand in response to the hot plugging of new devices. Modules also enable the
Building Modules
In the 2.6 kernel, building modules is easier than in previous versions, thanks to the new kbuild build system .The first decision in building modules is deciding where the module source is to live.You can add the module source to the kernel source proper, either as a patch or by eventually merging your code into the official .tree.Alternatively, you can maintain and build your module source outside the source tree.
Installing Modules
Compiled modules are installed into /lib/modules/version/kernel/, where each directory under kernel/ corresponds to the modules location in the kernel source tree. For example, with a kernel version of 2.6.34, the compiled fishing pole module would
live at /lib/modules/2.6.34/kernel/drivers/char/fis hing.ko if you stuck it directly in drivers/char/. The following build command is used to install compiled modules into the correct location: make modules_install This needs to be run as root.