Topics: 1. Embedded Basics 2. Linux Kernel Introduction 3. Kernel compilation and installation (x86) 4. The first module of 5. Related tools for modules 6. Symbol export for Module 7. Parameters of the module job: 1. Look at linux/module.h. Look at the header files that come into the course every day. The file is in the same location:/home/zshh/work/driver/kernel/linux-3.5/include/linux focus on the module structure (the count of the modules is in the block structure) Again module This structure contains the state of the modules, the definition of the initialization session function pointer of the module, and also the definition of the Exit function pointer. It also includes the operation of the kernel parameters, the struct Kernel_param *KP is defined as follows: struct kernel_param{const char *name; const struct Kernel parm_ops *op S U16 Perm; S16 level; Union {void *arg; const struct kparam_string *str;const struct kparam_array * ARR; }; }; const struct kernel parm_ops *ops; This function contains some operations related to read and 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. See __init macro # define __init _section (. Init.text) #define __section ( s) __attribute__ ((__section__ (#S))) This macro is most red replaced by __attribute__ ((__section__ (". Init.text") which means he will be stored again. Init.text , __initdata and other attribute flags, is to put this property code into the target file. Init.text section, data putinto. Init.data section-This process provides a xxx.lds link script for the relevant target platform to guide LD completion by compiling the kernel. The execution of this function is divided into two cases: one: When compiling as a module. When you use Insmod, or Modprob inserts the module into the kernel, he is executed. If the insert succeeds, the function of the __init property is executed; two: When the code is compiled into Zimage, The Do_basic_setup () function calls the Do_initcalls function when the kernel boots, and all functions of the. Init section are executed once. After initialization is complete, the memory of the function or data identified with these keywords is freed. Three: All __init functions have a pointer pointing to it in Initcall.init. 3. See Linux/list.h 4. The parameter of the experimental module bool type, test can use 0/1,y/n, etc. if the parameters of the module are an array, you need to use the Module_param_array macro to declare your own example and test the use of the macro 1. Embedded basic knowledge ======================= the current development of the embedded industry, the embedded system configuration and other 2.linux kernel description =======================kernel directory has two cores, One is a standard kernel downloaded from www.kernel.org, a kernel modified by Google, a Samsung ported core, a description of the directory structure after extracting the kernel, and an introduction to the core functions of the kernel 3. Compile and install the kernel (x86) ======================= ( 1) kernel configuration $>make menuconfig through the graphical interface (depending on the ncurses library), determine which parts of the compiled kernel are included. The final configuration result, stored in the. config file, determines whether the code is compiled, if compiled, compiled into Zimage, or compiled into a. Ko module (2) the compilation of the kernel compiles the $>make build Zimage kernel and the. Ko Module (3) Installation of the kernel module $> Make Modules_install the installation of the generated. Ko to a specific location on disk (that is, the copy) is typically the/lib/modules/xxx/directory (version of the kernel that is compiled by XXX) (4) The installation of the kernel $>make Install installs the generated zimage into 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 (see Luck) 4. First module========================= refer to mod_test01.c and makefile in the x86-drv/01mod/directory for a serious understanding of the role of each of these two files 5. Module related tools (5) ========================= (1) module manually loaded $>insmod Mod_test01.ko will call the module's entry function, if it is PRINTK information, use $>DMESG view (2) Manual unloading of the module $>rmmod mod_test01 (3) Displays the module information $>modinfo Xxx.ko (4) lists the modules that have been loaded in the kernel $>lsmod (5) Auto-load module module automatic loading tool. The 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 show PRINTK information $>dmesg-c clear the PRINTK buffer 6. Symbol export of the module ========== ================ to avoid namespace contamination, the kernel prescribes that all symbols in the. Ko module are local by default. Must be exported through Export_symbol macro before it has global properties; Export_symbol macros can be used for global functions and global variables; write 01mod/mod_test02.c and mod_test03.c generation modules Mod_test02.ko and Mod_test03.ko can be used insmod/ Rmmod or modprobe Test $>make Install//execute makefile Target install$>modprobe mod_test03 will load dependent mod_test02 also $>modprobe- R mod_test03 with-R to unload Module 7. Module Parameters ========================= use MODULE_PARAM macro to declare module parameter reference 01mod/mod_test04.c module parameter corresponds to the file is/sys/ The 3rd parameter of the Module/mod_test03/parameters/name and Valuemodule_param macros is used to determine the permission of these two files
Linux kernel module notes