Driver Module Loading

Source: Internet
Author: User

Enter the generated directory. insmod./Hello. Ko loads the driver.

Module size used
Hello 9472 0
Nls_iso8859_1 12032 0
Nls_cp437 13696 0
Vfat 18816 0
Fat 58272 1 vfat
Usb_storage 82880 0
Isofs 39844 1

Lsmod lists all drivers. Lsmod reads and analyzes the/proc/modules file.

CAT/proc/modules

Nls_iso8859_1 12032 0-live 0xe1bc6000
Nls_cp437 13696 0-live 0xe1bba000
Vfat 18816 0-live 0xe1bad000
Fat 58272 1 vfat, live 0xe1b50000
Information about loaded modules in the kernel exists in the SYS/Module Directory.

Go to the/sys/module directory tree-a to get the directory tree:

Usb_storage
| -- Drivers
| '-- USB: USB-storage->.../bus/USB/Drivers/USB-storage
| -- Holders
| -- Initstate
| -- Notes
| '--. Note. GNU. Build-ID
| -- Parameters
| -- Delay_use
| -- Option_zero_cd
| '-- Swi_tru_install
| -- Refcnt
| -- Sections
| --. BSS
| --. Data
| --. Exit. Text
| --. GNU. linkonce. this_module
| --. Init. Text
| --. Note. GNU. Build-ID
| --. Parainstructions
| --. Rodata
| --. Rodata. str1.1
| --. Rodata. str1.4
| --. Smp_locks
| --. Strtab
| --. Symtab
| --. Text
| -- _ Bug_table
| '-- _ Param
| '-- Srcversion

L/Drivers/Hello # modinfo hello. Ko
Filename: Hello. Ko
Alias: a simplest Module
Description: a simple hello World module
License: Dual BSD/GPL
Author: Barry song <21cnbao@gmail.com>
Srcversion: 3fe9b0fbafdd565399b9c05
Depends:
Vermagic: 2.6.28-11-generic SMP mod_unload modversions 586

Modprobe is used to mount a new module and a module on which the new module depends modprobe. Our common function is to mount a module. When a kernel module is mounted, the modules on which this module depends are also mounted; this is different from the insmod mounting module. Of course, modprobe also provides a list of all kernel modules, as well as the function of removing modules. Next we will give an example to illustrate our common functions and parameters;

Modprobe-codprobe-C can view the modules configuration file, such as the module alias;

Modprobe-L is used to list all modules in the kernel, including mounted and unmounted modules,

Read File:/lib/modules/'uname-R'/modules. Dep

We can check the required modules and mount them as needed;

[Root @ localhostbeinan] # modprobe Module name Note: mount a module;
[Root @ localhostbeinan] # modprobe-R module name Note: remove the loaded module, which has the same function as rmmod;

Ifneq ($ (kernelrelease),) # kernelrelease is not empty. It is valid when the second entry is made.
OBJ-M: = Hello. o
Hello-objs: = Main. o add. o
Else
Kdir: =/lib/modules/2.6.18-53/build

ALL:
Make-C $ (kdir) M = $ (PWD) Modules # enter the kdir directory and execute make modules
Clean:
Rm-f *. Ko *. o

Endif

Kernel module parameters: these parameters are included after the insmode installation module is executed.
Module_param (name, type, Perm) parameter name, parameter type, access permission
Perm common value: s_irugo: any user has read permission for this parameter in/sys/module.
S_iwusr: the root user has read permission on the parameter displayed in/sys/module.
Int A = 3; // initialize the default value.
Module_param (A, Int, s_iwuser );
This parameter can be used in the kernel.
The function implemented in module A must be exported using export_symbol before it can be called by other modules. The exported list is in the proc/kallbyms file.
Export_symbol (function );
The difference between the kernel module and the application is that after the kernel is installed, it will always reside in the memory. As a service, it will serve a certain request in the future until it is uninstalled.

The function is called.
Printk (kern_emer, "emergc"); // contains the print level

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.