Adding the device driver

Source: Internet
Author: User
Article title: adding a device driver. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Author: Qiang Lei
  
The driver can be compiled in two ways. one is to statically compile the program into the kernel, and the other is to compile the program into a module for dynamic loading. UCLinux does not support dynamic module loading, and embedded Linux cannot use insmod/rmmod to load and Uninstall Device drivers as flexibly as desktop Linux does, so here we will only introduce how to statically compile the device driver into the uCLinux kernel.
  
The following uses UCLinux as an example to describe how to compile the driver test. c in the module mode into the kernel:
  
(1) modify the test. c source code
  
Step 1:
  
# Include
# Include
  
  
Char kernel_version [] = UTS_RELEASE;
  
Changed:
  
# Ifdef MODULE
# Include
# Include
Char kernel_version [] = UTS_RELEASE;
# Else
# Define MOD_INC_USE_COUNT
# Define MOD_DEC_USE_COUNT
# Endif
  
  
Step 2: Create the int init_test (void) function)
  
Register the device here:
  
Result = register_chrdev (254, "test", & test_fops );
  
(2) set test. copy c to the/ucLinux/Linux/drivers/char directory, and mem in the/ucLinux/Linux/drivers/char directory. in c, add the following code to the int chr_dev_init () function:
  
# Ifdef CONFIG_TESTDRIVE
Init_test ();
# Endif
  
  
(3) add the following code to Makefile in the/ucLinux/Linux/drivers/char Directory:
  
# Ifdef CONFIG_TESTDRIVE
Init_test ();
# Endif
  
  
(4) add the following code to the character device segment in config. in the/ucLinux/Linux/arch/m68knommu Directory:
  
Bool 'support for testdrive 'CONFIG_TESTDRIVE y
  
(5) run make menuconfig (in the menuconfig character device options, you can see the 'support for testdrive 'option we just added and has been selected); make dep; make Linux; make Linux. text; make Linux. data; cat Linux. text Linux. data> Linux. bin.
  
(6) create a device in the/ucLinux/romdisk/dev/directory:
  
Mknod test c 254 0
  
Run make in/ucLinux/javasrc/to generate a new Romdisk. s19 file.
  
By now, adding a device driver in UCLinux can be said to be completed, as long as the new Linux. bin
  
With Romdisk. s19 burned into the target board, you can use your new device test.
  
  

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.