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.
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 the driver test in the module mode. C is based on a series of steps to compile it into the kernel: (1) Change test. the first step of the C source code is to change the original: # include char kernel_version [] = uts_release; To: # ifdef Module # 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 to register the device here: Result = register_chrdev (254, "test", & test_fops ); (2) Set test. copy C to/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) in the/uClinux/Linux/ARCH/m68knommu directory config. add the following code to the character device segment of in: bool 'support for testdrive 'config_testdrive y (5) run make menuconfig. (In the character device options of menuconfig, you can see the newly added 'support for testdr. Ive 'option, and has been selected); Make Dep; 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 and 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.