Linux module programming experience-general Linux technology-Linux programming and kernel information. See the following for details. 1. Makefile format
In the 2.4 kernel, you can directly set the kernel source file path (gcc-I option setting) to compile the module code. However, in the 2.6 kernel, make linux + make modules + make modules_install first, then there will be a kernel code tree under/lib/modules/kernel release number/, and then the following Makefile can be compiled (the file name must be Makefile rather than makefile)
Obj-m: = driver. o # Name of the driver to be output
KDIR =/lib/modules/$ (shell uname-r)/build # build is actually a symbolic connection pointing to the location of the kernel code tree
PWD = $ (shell pwd) # current path
Modules:
$ (MAKE)-C $ (KDIR) M = $ (PWD) modules # I don't understand what this line means. I will take a look at it later.
Clean:
$ (RM) *. o *. ko *. symvers *. mod. c # delete all temporary files and output files
2 MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT
In the 2.4 kernel, module. h already has these two macros, and 2.6 is no longer available (FC3, but other cores are not visible). You need to define them as follows:
3. Replace printk () in the kernel code ()
In some kernels, printk () cannot output information on the console (klogd, syslogd, or printk () is running with a low priority). You can use the following method to directly output the information to the console:
Current represents a pointer of the current process (struct task_struct *). It contains the struct tty_struct * tty pointer under 2.4 and calls tty-> write () to output information to the console, however, in the 2.6 kernel, current does not contain the tty pointer, but contains a struct signal * signal pointer, which contains the tty pointer. The Code is as follows:
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