How to add your own drivers under Linux

Source: Internet
Author: User

In this Linux-driven development, a network approach is introduced to introduce two ways to drive development:
I. Driver compilation to the kernel
1. First select a location to place the driver code, for example: DRIVERS/CHAR/XXX.C
2. Add the following to the Drivers/char/kconfig file:
Menu "XXX Support"
Config xxx
TriState "XXX Support"
---help---
XXX use GPIO as IR input.
If you want XXX support, you should say Y here and also to the
Specific driver for your bus adapter (s) below.
This XXX support can is built as a module.
Endmenu
3. Write makefile with the same position as above (drivers/char/), with the following contents:
obj-$ (config_xxx) + = XXX.O//black xxx with the above kconfig in the same xxx, and red xxx should be with
The driver xxx.c is named the same
4. Modify the previous level makefile and kconfig//according to their own position to make the corresponding changes, refer to the superior mak_
Contents of Efile and Kconfig
At this point, the modification is complete, at this time you can use make menuconfig, found that there is a XXX support---> Options, enter after the selection m, then make modules, to the Char directory, has generated Xxx.ko.
Finally, go to make menuconfig, select XXX Support, compile into the kernel.
Two. Driver Module loading
Generally in the development of this method is more convenient, do not need to download the kernel through TFTP every time, NFS to mount the root filesystem, we only need to use the driver as a module, in the local virtual machine to complete the operation.
1> module production
A. Driver compilation
Put the xxx.c file into the Drivers/char subdirectory and modify the Drivers/char/makefile
Obj-m + = XXX.O
And then
Make modules, the build module is Drivers/char/xxx.ko
Then put the Xxx.ko into the/lib/modules/2.6.14.1 (own kernel version)/directory of the single Board root filesystem
B. Drive Test
Write the test code and makefile file, make, put the generated file in the single board and file system/usr/bin/directory
2>. debugging
To create a device file in the root file system:
# Mknod/dev/buttons C 232 0
Loading modules
# Insmod S3c24xx_buttons

Uninstalling the module
# Rmmod S3c24xx_buttons

How to add your own drivers under Linux

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.