Overview of Linux driver framework and driver loading

Source: Internet
Author: User
Article title: describes the driver framework and driver loading in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

This section describes the Linux device driver framework, driver configuration files, and common methods for loading drivers. It also describes how Red Hat Linux installer loads drivers, we can put the driver into the boot disk by ourselves; after installing the system, we can use kudzu to automatically configure the hardware program.

  Linux device driver overview

1. kernel and driver module

The operating system controls hardware through various drivers. It shields users from a variety of devices. the driving hardware is the most basic function of the operating system and provides a unified operation mode. Just as when we look at the documents on the screen, we don't have to worry about whether to use the nVIDIA chip or the display card of the ATI chip. after entering the command, we only need to know that the required text is displayed on the screen. The hardware driver is the most basic component of the operating system and also occupies a high proportion in the Linux kernel source program.

The Linux Kernel adopts a Loadable modular design (LKMs and Loadable Kernel Modules). Generally, the compiled Linux Kernel supports plug-in Modules, that is, compile the most basic core code in the kernel. other code can be either in the kernel or compiled into a module file of the kernel.

If you need a function, such as accessing an NTFS partition, load the corresponding NTFS module. This design can make the kernel file not too large, but also support a lot of features, dynamic loading if necessary. This is not the same as the microkernel design, but it is a practical kernel design solution.

Our common drivers are dynamically loaded as kernel modules, such as sound card drivers and Nic drivers, while Linux's most basic drivers, drivers such as CPU, PCI bus, TCP/IP protocol, APM (Advanced Power Management), and VFS are compiled in the kernel file. Sometimes kernel modules are called drivers, but the driver content is not necessarily hardware, such as the driver of the ext3 file system.

It is important to understand this. Therefore, the kernel module is loaded when the driver is loaded. Next, let's take a look at the commands related to the modules and use them when loading drivers: lsmod, modprob, insmod, rmmod, and modinfo.

Lsmod lists the modules loaded in the current system, for example:

       
        
# Lsmod (consistent with cat/proc/modules) Module Size Used by Not taintedradeon 115364 1 agpgart 56664 3 nls_iso8859-1 3516 1 (autoclean) loop 12120 3 (autoclean) smbfs 44528 2 (autoclean) parport_pc 19076 1 (autoclean) lp 9028 0 (autoclean) parport 37088 1 (autoclean) [parport_pc lp] autofs 13364 0 (autoclean) (unused) ds 8704 2 yenta_socket 13760 2 pcmcia_core 57184 0 [ds yenta_socket] tg3 55112 1 sg 36940 0 (autoclean) sr_mod 18104 0 (autoclean) microcode 4724 0 (autoclean) ide-scsi 12208 0 scsi_mod 108968 3 [sg sr_mod ide-scsi] ide-cd 35680 0 cdrom 33696 0 [sr_mod ide-cd] nls_cp936 124988 1 (autoclean) nls_cp437 5148 1 (autoclean) vfat 13004 1 (autoclean) fat 38872 0 (autoclean) [vfat] keybdev 2976 0 (unused) mousedev 5524 1 hid 22212 0 (unused) input 5888 0 [keybdev mousedev hid] ehci-hcd 20104 0 (unused) usb-uhci 26412 0 (unused) usb core 79392 1 [hid ehci-hcd usb-uhci] ext3 91592 2 jbd 52336 2 [ext3]
       

The above shows the loaded modules in the current system. The first column on the left is the module name, the second column is the module size, and the third column is the number of modules used.

If unused is followed, it indicates that this module is not in use currently. If autoclean is followed, the module can be automatically cleaned by the rmmod-a command. The rmmod-a command uninstalls the autoclean module. if a module is not used at this time, it is marked as autoclean. If a module name exists in [] brackets at the end of a row, the module in brackets depends on this module. For example:

       
        cdrom 34144 0 [sr_mod ide-cd]
       

The ide-cd and sr_mod modules depend on the cdrom module.

The system module files are stored in the/lib/modules/2.4.XXX/kerne directory, which are in the fs, net, and other sub-directories by category, their interdependence is stored in/lib/modules/2.4.XXX/modules. in the dep file.

Note that this file not only writes the dependency between modules, but also the kernel Search module is in this file. you can use the modprobe command to intelligently insert modules based on the dependency between modules, and/etc/modules. the content smart insertion module in the conf file. For example, if you want to load the drive of the ide, run the following command:

       
        # modprobe ide-cd
       

In this case, the cdrom module is automatically inserted.

Insmod is also a command for inserting modules, but it does not automatically resolve dependencies. Therefore, the command used to load kernel modules is modprobe.

Rmmod can delete modules, but it can only delete unused modules.

Modinfo is used to view module information, such as modinfo-d cdrom. in Red Hat Linux, the module-related commands are in the RPM Package of modutils.

[1] [2] [3] [4] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.