Linux Kernel module notes, Linux kernel module

Source: Internet
Author: User
Tags dmesg

Linux Kernel module notes, Linux kernel module

Topic: 1. basic embedded knowledge 2. linux Kernel Introduction 3. kernel compilation and installation (x86) 4. first Module 5. module related tools 6. module symbol export 7. module parameter job: 1. check linux/module. h. The location of the header file that is exposed to the course every day: /home/zshh/work/driver/kernel/linux-3.5/include/linux focuses on the module struct (module counts are in the module struct) and module this struct contains the module status, the definition of the module's initialization function pointer is also defined by the exit function pointer. it also includes operations on kernel parameters. The struct kernel_param * kp is defined as follows: struct kernel_param {const char * name; const struct kernel parm_ops * ops; b2perm; s16 level; union {void * arg; const struct kparam_string * str; const struct kparam_array * arr ;}; const Struct kernel parm_ops * ops; this function contains operations related to read/write parameters. struct kernel_param_ops {int (* set) (const char * val, const struct kernel_param * kp) int (* set) (char * buffer, const struct kernel_param * kp) void (* free) (void * arg)} 2. look at _ init macro # define _ init _ section (. init. text) # define _ section (s) _ attribute _ (_ section _ (# S ))) the redmost macro is replaced by _ attribute _ (_ section __(". init. text ") indicates that it will be stored again. init. text. _ init, _ init Data and other attribute flags need to put the code of this attribute into the target file. init. text section, data. init. data Section-this process provides xxx for the target platform by compiling the kernel. the lds link script guides ld to complete. // This function can be executed in two ways: 1. When compiled as a module. when insmod or modprob is used to insert a module to the kernel, It will be executed. if the insert is successful, the _ init attribute function is executed. 2. When the code is compiled into zImage, The do_basic_setup () function is executed to call the do_initcils function ,. all functions in the init section will be executed once. after initialization, the memory occupied by the functions or data identified by these keywords will be released. III. All _ init functions are stored in initcall. each init has a pointer pointing to it. 3. see linux/list. h 4. the bool type of the Experiment Module parameters can be used to test whether 0/1, y/n, etc. If the module parameters are arrays, you need to use the module_param_array macro to declare your own write example, test the usage of the macro. basic embedded knowledge =. linux kernel instructions =================================== there are two kernels in the kernel directory, one is the standard kernel downloaded from www.kernel.org, and the other is the kernel modified by google and transplanted by Samsung. After extracting the kernel, describe the directory structure and introduce the core functions of the kernel 3. kernel compilation and installation (x86) =========================== (1) kernel configuration $> make menuconfig determines the compiled kernel through the graphical interface (dependent on the ncurses Library) Which parts are included. The final configuration result is stored in. the config File determines whether the code is compiled. If it is compiled, it is compiled into zImage or compiled. ko module (2) kernel compilation $> make compilation to generate zImage kernel and. ko module (3) kernel module installation $> make modules_install will generate. ko is installed on the disk at a specific location (that is, copy). It is generally/lib/modules/xxx/directory (xxx is the version of the compiled kernel) (4) kernel installation $> make install the generated zImage to the/boot directory (zImage is called bzImage on x86 and is located in the arch/x86/boot/directory) next, you can restart the system to see if the newly compiled kernel can be used (depending on luck) 4. the first module ====================================== reference mod_test01.c and Makefile under the x86-drv/01mod/directory seriously understand the role of each part of the two files. module related tools (5) = ========================================= (1) manual loading of the module $> insmod mod_test01.ko will call the module's entry function. If it is printk information, use $> dmesg to view (2) manual uninstallation of the module $> rmmod mod_test01 (3) display Module Information $> modinfo xxx. ko (4) lists modules loaded in the kernel $> lsmod (5) automatic loading tool for module modules. This tool can automatically load the modules that the module depends on. Modprobe can only load modules under/lib/modules/xxx. $> Modprobe xxx // load $> modprobe-r xxx // uninstall tip: $> dmesg displays printk Information $> dmesg-c clears printk buffer 6. module symbol export ======================== to avoid namespace pollution, the kernel rules ,. all symbols in the ko module are local by default. The global attribute is available only after the EXPORT_SYMBOL macro is exported. The EXPORT_SYMBOL macro can be used for global functions and global variables; write 01mod/modules and mod_test03.c to generate modules mod_test02.ko and mod_test03.ko. You can use insmod/rmmod or modprobe to test $> make install // to execute the target install $> modprobe mod_test03 in Makefile. load $> modprobe-r mod_test03. Use-r to uninstall the module. 7. module parameters ============================== use the module_param macro to declare module parameters refer to 01mod/mod_test04.c module Parameters the corresponding file is the 3rd parameters of the/sys/module/mod_test03/parameters/name and valuemodule_param macro, to determine the permission of these two files.

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.