Take Mini2440 For example, its Linux kernel directory is/opt/friendlyarm/mini2440/ linux-2.6.32.2, under linux-2.6.32.2 (Linux kernel directory), under the drivers directory, the new directory is named Add_sub_kconfig.
To create a new file add_sub.c,add_sub.h,test_communication.c in the Add_sub_kconfig directory, the code is as follows: (Example from "Introduction and practice of Linux Driver Development 2nd edition")
#ifndef Add_sub_h #define Add_sub_hLong add_integer (intint b); long sub_integer (intint b); #endif
#include <linux/init.h>#include<linux/module.h>#include"Add_sub.h"LongAdd_integer (intAintb) { returnA +b;}LongSub_integer (intAintb) { returnAb;} Export_symbol (Add_integer); Export_symbol (Sub_integer); Module_license ("GPL");
#include <linux/init.h>#include<linux/module.h>#include"Add_sub.h"Static intA =1;Static intb =1;Static intAddorsub =1;Static intTest_init (void){ intresult =0; PRINTK ("Test init\n"); if(Addorsub = =1) {result=Add_integer (A, b); } Else{result=Sub_integer (A, b); } PRINTK ("The %s result is%d\n", addorsub = =1?"ADD":"Sub", result); return 0;}Static voidTest_exit (void) {PRINTK ("Test exit\n");} Module_init (Test_init); Module_exit (test_exit); Module_param (A,int, S_irugo); Module_param (b,int, S_irugo); Module_param (Addorsub,int, S_irugo); Module_license ("GPL");
Create a new Kconfig file in the Add_sub_kconfig directory with two modules, where a menu is constructed to include them. The tristate indicates that the module can be either compiled into the kernel or as a standalone module, and the default value m represents a separate module. If you want to compile directly into the kernel, you can use a Boolean and then change the default value to Y.
" add_sub_function " "add_sub_function" config add_sub "add_sub Support" default mconfig test_communicationa " Add_sub TestSupport" depends on add_sub default Mendmenu
Create a new makefile file in the Add_sub_kconfig directory, write add_sub and test_communication after config in Kconfig, and write Config_add_sub and config_test_ here Communication:
obj-$ (config_add_sub) + = add_sub.oobj-$ (config_test_communication) + = TEST_COMMUNICATION.O
Add the following in the Kconfig file in the drivers directory:
SOURCE "Drivers/add_sub_kconfig/kconfig"
Add the following in the makefile file in the drivers directory:
obj-$ (config_add_sub) + = add_sub_kconfig/
obj-$ (config_test_communication) + = add_sub_kconfig/
Go back to the/opt/friendlyarm/mini2440/linux-2.6.32.2 directory and execute:
Make Menuconfig, and then confirm that the module you added is already open. (choose m to compile the KO module here)
Make modules to see the two KO files compiled in the Add_sub_kconfig directory.
Download the two KO files to Mini2440 for testing.
Linux to write a driver module that communicates with each other and add it to the kernel