I have developed 2 kernel drivers and I can build them using yocto as dynamic kernel modules without any probem but when I need to build them as static I had some issue related to dependency, because my driver1 is used by driver2.
Here is the issue:
| drivers/built-in.o: In function `init_module':
| mydriver2.c:(.init.text+0xd474): undefined reference to `__this_module'
| drivers/built-in.o: In function `mydriver_two_init':
| mydriver2.c:(.init.text+0xd53c): undefined reference to `my_driver_fn'
| /bsp/build/tmp/work-shared/bsp/kernel-source/Makefile:1003: recipe for target 'vmlinux' failed
| make[2]: *** [vmlinux] Error 1
| Makefile:152: recipe for target 'sub-make' failed
| make[1]: *** [sub-make] Error 2
| Makefile:24: recipe for target '__sub-make' failed
| make: *** [__sub-make] Error 2
In my driver1 I have developed a function that it is exported using EXPORT_SYMBOL(my_driver_fn);
and this function is used in driver2.
I have tried to Kconfig file but error still exist : Kconfig file :
menu "personal Driver "
comment "Personal driver Config"
config DRIVER_ONE
bool "driver 1"
default y
help
driver 1
config DRIVER_TWO
bool "driver 2"
depends on DRIVER_ONE
default y
help
driver 2
endmenu
folder tree :
linux-sources
\----->drivers (Makefile updated with obj-$(CONFIG_DRIVER_ONE) += driver_one/ and obj-$(CONFIG_DRIVER_TWO) += driver_two/)
|------------->personaldrivers
\--->Kconfig
\--->driver_one----contains---> mydriver1.c and Makefile (obj-$(CONFIG_DRIVER_ONE) = mydriver1.o)
\--->driver_two----contains---> mydriver2.c and Makefile(obj-$(CONFIG_DRIVER_TWO) = mydriver2.o)