How to add your own device drivers in embedded Linux

Source: Internet
Author: User
Article Title: how to add your own device driver in embedded Linux. 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.
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. Because uClinux does not support dynamic module loading, and embedded LINUX cannot use insmod/rmmod 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:
Ifeq ($ (CONFIG_TESTDRIVE), y)
L_OBJS + = test. o
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.
  
Here, adding a device driver in UCLINUX can be said to be completed, as long as the new linux. bin and Romdisk. s19 is burned into the target board, and you can use your new device test.
  
  
Related Article

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.