This article is mainly to a simple LED-driven development process, to spy on the Linux driver development.
Basic process:
1. Write driver files xxxx.c
The main purpose of this file is to initialize the device hardware, mainly Xxx_init (), which also includes the registration of the device.
To initialize the file_operations structure, this initialization is the core, in fact, to find the mapping function of Open.write.read function.
The compilation of various mapping functions, such as Xxx_open (), Xxxx_write (), Xxx_read (), etc.
2. After the completion of the driver file, put the file into the "kernel", the path is Linux-2.6.xxx/driver/char (depending on the device type, choose character or block type). This example is clearly a character-type device.
3. Add one line to the/drivers/char/makefile:
Obj-m + = XXXX.O (xxxx is the driver file name in Process 1)
4. Execute the "Make modules" command under the kernel directory to generate Xxx.ko under/drivers/char
5. Download the Xxx.ko to the/LIB/MODULES/2.6.XXX directory of the Development Board equipment.
6. Execute "modprobe xxx" to load the driver module into the Linux kernel of the Development Board. If you want to uninstall the driver module, you can execute the command "Rmmod xxx".
7. Use the command Mknod to create a device file in the Development Board. This is particularly important, which is equivalent to creating a "handle" or "path" for the driver file, so that when the application wants to use the drive, it needs to open the corresponding device with open, and the path in open is the handle.
Command: Mknod name {b | c} Major Minor, where name is the device name, B or C is the device type, Major is the primary device number, and Minor is the secondary device number. For example: Mknod/dev/leds C 231 0
8. At this point, the driver has been developed, if you want to use the driver, you need to develop applications, such as TEST.C, in test mainly to open the corresponding device, and then use the corresponding device.
Command: Open (constchar*pathname,intflags); You can see from the name pathname is the device path, intflags is the open type. Then flow 7, for example: open ("/dev/leds", 0);