The sixth chapter:
1 , what is a driver:
a , the most important step in writing a Linux driver is to write a callback function, otherwise the data that interacts with the device file will not be processed;
2 , the steps to write a Linux driver:
a , build Linux drive skeleton (load and unload Linux drivers);
Module_init and Module_exit;
b , registering and unregistering device files:
Complete the setup of the device file Misc_register in the initialization function;
C , specifying the information related to the drive;
D , specifying a callback function;
e , writing business logic;
F , write the makefile file (the Linux kernel source code editing rules are defined by the makefile file);
g , write Linux driver: Linux driver can directly compile the kernel, can also be used as a touch board to compile separately;
h , install and uninstall Linux drivers;
3 , the first Linux driver:
a , preparation of Linux drivers;
b , writing the skeleton of the Linux driver (Initialize and exit drivers):
Linux The system divides the memory into the user space and the kernel space, these two space programs cannot directly access, the printf function runs in the user space, the PRINTK function runs in the kernel space. If the user-space program is to access the kernel-space driver, the user-space program interacts with the driver through the device file.
Install linux driver: #insmod Word_count.ko
to see if Word_count was installed successfully: #lsmod | grep word_count
Uninstall Linux driver: #rmmod word_count
View log information from Linux-driven output: #dmesg | grep word_count/tail-n 2;
C , specifying driver-related information:
perform #modinfo Word_count.ko to view the Word_count.ko information. Depends table current-driven dependency, vermagic indicates which Linux kernel version the current Linux drive template is compiled under.
D , registration and cancellation of equipment files;
e , specifying a callback function
File_operations.read File_operations.write a member variable can specify a callback function pointer to be called by a read-write device file.
F , the realization of the algorithm of statistical words;
g , compile, install, and uninstall Linux-powered programs.
4 , testing Linux drivers in several ways:
a , using Ubuntu Linux to test Linux drivers;
b , test Linux drivers with native C programs in the Android emulator;
Android emulator in the direct running normal Linux program two conditions: Android simulator, board or mobile phone requires root permission, executable files need cross compiler to compile, so that support arm processor.
C , using the Android NDK to test Linux drivers;
D , using Java code to test the device files directly to measure the Linux driver;
e , using Eclipse to develop and test Linux drivers.
Sixth Chapter Essays