Take two C files as an example:
The adc_device.c, Adc_ driver.c, which should have been compiled separately into adc_Device.ko and adc_Driver.ko, are compiled into a KO file!
Method of Adoption:
First step, modify C file
1, remove adc_device.c file module_init (XXX), Module_exit (yyy) in the XXX, yyy function prototype keyword static
2, Logout adc_device.c file module_init (XXX), module_exit (yyy) function
3. Add the above xxx, yyy functions declared with the keyword extern in the adc_driver.c file.
4, in adc_driver.c file Module_init (mmm), Module_exit (nnn) in the MMM, NNN function prototype appropriate place to call XXX, yyy function
Note: When compiling multiple C files into a. ko file, the module_init and module_exit in the C file will prompt for redefinition,
So a KO inside can only have a module_init and a module_exit!
Step two, write the Makefile file (Key section)
Obj-m + = ADC.O
ADC-OBJS: = ADC_DEVICE.O adc_driver.o
In this way, the adc_device.c, ADC_DRIVER.C, which should have been compiled separately into Adc_device.ko and Adc_driver.ko
Compile into a Adc.ko file!
The Linux kernel driver compiles multiple C files into a KO file--each C file has Module_init and Module_exit