Writing a kernel module and make concepts
Hi,
i have written some really basic loadable kernel modules. There are a couple of concepts that i'll like to get cleared. In a tutorial, the Makefile was given as follows- obj-m += try.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean I understand that -C option of 'make' changes the current directory to /lib/modules/$(shell uname -r)/build (which depends on my kernel). Now, my question is why to change to that particular directory? Also M=$(PWD) will hold the dir where i have written the module. Why is it required? What does 'modules' at the end of that line indicate? Q2> We need to include <linux/module.h> and <linux/kernel.h> in a module. If i am right, the module uses kernel headers for these definitions. But how does 'make' find these definitions. Q3> We are planning to write a custom scheduler for linux kernel. cat /sys/block/sda/queue/scheduler gives us the currently loaded schedulers. How do we expose our scheduler to linux kernel so that we can use it by switching to it. |
Is this question in wrong section??
|
make works only on Makefiles in the current working directory. The '-C' option tells make to first go to the specified directory, and use the specified target in the Makefile in that directory. This give make the capability of recursive building. The 'target' is one of the tokens at the left margin and followed by a ':' in a Makefile. The tokens 'modules' and 'clean' are such targets. Specifying a certain target tells make what part of the Makefile recipe it supposed to follow.
Make doesn't know how to find any C header files. Only C compilers know how to find header files. You may write rules in a Makefile that add to the C compilers list of places to look for header files. To see how to add your scheduler, look through the Makefiles for an existing kernel, and see how the existing schedulers are enumerated. Add yours to the Makefile using a similar format. It may also require adding accordant entries to the kernel .config file. A good understanding of the make tool is a valuable asset as a software developer. As a kernel developer, it is probably essential. I recommend finding one or more tutorials online to help you. Also, the man page for make has useful information. --- rod. |
... Another example ..
http://www.linuxquestions.org/questi...rnel-660415/#4 Code:
obj-m := lpptest.o |
All times are GMT -5. The time now is 02:56 PM. |