Steps to write a Linux driver
1th Step: Build Linu x Drive skeleton (load and unload Linu x drive)
2nd step: Registering and unregistering device files
3rd Step: Specify driver-related information
4th step: Specify the callback function
5th step: Writing Business logic
6th step: Writing the Makefile file
7th step: Compiling Linux drivers
8th step: Install and Uninstall Linux drivers
Preparation before writing Linux drivers
The Linux driver source code in this example is not put together with the Linux kernel source code, but is placed in a separate directory. First use the following command to build the directory where the Linux driver is stored. # mkdir-p/root/drivers/ch06/word Count # Cd/root/drivers/ch06/word Count then, use the following command to build the driver source code file (Word count.c) II Ech. "> Word count. C finally write a Makefile file, which is actually the 6th step in writing the Linux driver described in section 6.2. When you are familiar with the steps for writing Linux drivers, you can write Linux drivers without following the sequence described in section 6.2. # echo ' obj-m: = WORD_COUNT.O ' > Makefile where obj-m means compiling the Linux driver as a module (. ko file). If you use Obj-y, the Linux driver is compiled into the Linux kernel. Obj-m or obj-y need to use ": =" assignment. If the value of Obj-m or obj-y is WORD_COUNT.O, the make command compiles word count.c or word counts files from the Linux driver source directory into a word count.o file. If you use Obj-m, WORD_COUNT.O is connected to the Word_count.ko file and then loads modprobe using the Insmod or Word_count.ko command. If firewood uses obj-y, WORD_COUNT.O will be connected to the built-in. o file and will eventually be connected to the kernel. Where the BUILT-IN.O file is an intermediate destination file generated by a. o file that is connected to a class of programs. For example, all character device drivers will become a built-in. o file for the lifetime of the parent. Readers can find a B-Hill lt-in.o file in the <linux Kernel tour code directory 〉/by Ivers/char directory. The target file contains all the character drivers that can be connected to the Linux kernel (the Make Menuconfig command allows you to configure whether each driver and other kernel programs are allowed to be compiled into the kernel, see 4 for the technology for configuring the Linux kernel. Section 2.4). If the Linux driver relies on other programs, such as PROCESS.C, DATA.co needs to write the Makefile file as follows: Bj-m: Word_c. Unt. 。
Word_count-y: = PROCESS.O DATA.O
Where dependent files are specified using Module-y or module "OBJS". Module represents the name of the block, such as Word_count.
Android Deep Explore sixth chapter