Equipment and modules:
Device type: Block Device (Blkdev), character device (CDEV), network device;
Module:
Analyze the Hello,world module code. Hello_init is the entry point of the module, registered to the system via Module_init (), called when the kernel is loaded, is a macro call, and the only parameter is the initialization function of the module. Module initialization function Format: int my_init (void), can be marked as static type. The initialization succeeds with a return value of 0 and does not successfully return a non-0 value. The INIT function also registers resources, initializes hardware, allocates data structures, and so on.
The Hello_exit () function is the Exit function of the module, which is registered to the system by the Module_exit () routine, and the kernel calls Hello_exit () when the module is unloaded from memory. Exit functions must conform to the following form: void My_exit (void), Module_license (), and Module_author () are brief descriptions of the modules.
Building the module:
1, placed in the kernel source tree (This is not detailed introduction)
2, placed outside the kernel code:
To create a makefile file in your own source tree directory, you only need one line of instruction: obj-m: = XX.O (if there are multiple source files, use obj-m: = XX.O Xx-objs: = XX-MAIN.O xx-line.o), compile to generate Xx.ko. Also, tell make how to find the kernel source file and the underlying makefile file: make–c/kernel/source/location subdirs= $PWD Modules
Installation module: Make
Loading module: Insmod Xx.ko
Unload module: Rmmod Xx.ko
Module parameters: Module_param (name,type,perm);
Export symbol table: Export_symbol () and EXPORT_SYMBOL_GPL (). The Exported kernel symbol table is considered an exported kernel interface, even called the kernel API.
Device Model:
Kobject (Kernel object) is a struct kobject struct. Kobject is a hierarchy in which objects can be created. Ktype is a Kobject object that is associated to a particular type. The existence of Ktype is to describe the universal characteristics of a family of kobject. Kset is a collection of Kobject objects. Kobject, Kytpe, kset relationship: Kobject is associated with a special Ktype object, and Kobject is grouped into a collection called Kset.
Managing and manipulating Kobject:
Kobject is initialized through the function Kobject_init, and next calls Kobject_create () to create Kobject.
Reference count:
The main function of Kobject is to provide a unified reference counting system.
SYSFS:
The Sysfs file system is an in-memory virtual file system that gives us a view of the hierarchy of Kobject objects.
"Linux Textbook" Reading notes Chapter 17th module