I have a design for two kernel loadable modules that I am building out of tree. These modules may run independently or they may work together (use the services of each other) when both are loaded.
So I have module1.ko with funcA and funcB. I also have module2.ko with funcC and funcD. When module1.ko is loaded by itself, it simply uses funcA and funcB. But if module2.ko is also loaded, I would like to make it so that module1.ko can use funcC.
How can module1.ko detect if module2.ko is loaded so that it knows if funcC is available for it to use?
Also, since I'm building both of these modules outside of the Linux Kernel, how do I update my Makefile to add this conditional dependency at build time?
My Makefile currently looks something along the lines of this:
MODULE_NAME=module1
SOURCE_FILES=module1_driver.c
CROSS_COMPILER=powerpc-timesys-linux-gnu-
ARCH=powerpc
ifneq ($(KERNELRELEASE),)
obj-m := $(MODULE_NAME).o
$(MODULE_NAME)-objs := $(SOURCE_FILES:.c=.o)
ccflags-y := -I$(src)/../common
sinclude $(TOPDIR)/Rules.make
else
KERNELDIR ?= ../../linux/2.6-xlnx-rt
PWD := $(shell pwd)
default:
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILER) -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILER) -C $(KERNELDIR) M=$(PWD) clean
rm -rf ../common/*.o module1_test
endif