Results 1 to 7 of 7
Hi,
I am new to the kernel world and to this forum. Did a search on the forum but did not find an answer. Would appreciate any insights/advice/suggestion/solution for the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-28-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
Compiling custom drivers on Ubuntu10.04
Hi,
I am new to the kernel world and to this forum. Did a search on the forum but did not find an answer. Would appreciate any insights/advice/suggestion/solution for the following problem.
I was trying to write a helloworld driver as suggested here: (cyberciti.biz/tips/compiling-linux-kernel-module.html). So I created foodriver.c (instead of foo.c) accordingly and went ahead with a "make". It gave the following error:
----------------------------------------------------
----------------------------------------------------------------Code:make -C /lib/modules/2.6.32-24-generic/build M=/home/myd/code/drivers/foo modules make[1]: Entering directory `/usr/src/linux-headers-2.6.32-24-generic' CC [M] /home/myd/code/drivers/foo/foodriver.o In file included from include/linux/gfp.h:4, from include/linux/kmod.h:22, from include/linux/module.h:13, from /home/myd/code/drivers/foo/foodriver.c:1: include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or directory include/linux/mmzone.h:258:5: warning: "MAX_NR_ZONES" is not defined include/linux/mmzone.h:260:7: warning: "MAX_NR_ZONES" is not defined include/linux/mmzone.h:262:7: warning: "MAX_NR_ZONES" is not defined In file included from include/linux/gfp.h:4, from include/linux/kmod.h:22, from include/linux/module.h:13, from /home/myd/code/drivers/foo/foodriver.c:1: include/linux/mmzone.h:300: error: ‘MAX_NR_ZONES’ undeclared here (not in a function) /home/myd/code/drivers/foo/foodriver.c:18: fatal error: opening dependency file /home/myd/code/drivers/foo/.foodriver.o.d: Permission denied compilation terminated. make[2]: *** [/home/myd/code/drivers/foo/foodriver.o] Error 1 make[1]: *** [_module_/home/myd/code/drivers/foo] Error 2 make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-24-generic' make: *** [all] Error 2
I saw a "Permission denied" in the output and so went ahead with "sudo make" instead of "make" (this is what I usually do when I see Permission denied).
Got the following error:
------------------------------------------------
-----------------------------------------Code:make -C /lib/modules/2.6.32-24-generic/build M=/home/myd/code/drivers/foo modules make[1]: Entering directory `/usr/src/linux-headers-2.6.32-24-generic' CC [M] /home/myd/code/drivers/foo/foodriver.o In file included from include/linux/gfp.h:4, from include/linux/kmod.h:22, from include/linux/module.h:13, from /home/myd/code/drivers/foo/foodriver.c:1: include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or directory include/linux/mmzone.h:258:5: warning: "MAX_NR_ZONES" is not defined include/linux/mmzone.h:260:7: warning: "MAX_NR_ZONES" is not defined include/linux/mmzone.h:262:7: warning: "MAX_NR_ZONES" is not defined In file included from include/linux/gfp.h:4, from include/linux/kmod.h:22, from include/linux/module.h:13, from /home/myd/code/drivers/foo/foodriver.c:1: include/linux/mmzone.h:300: error: ‘MAX_NR_ZONES’ undeclared here (not in a function) make[2]: *** [/home/myd/code/drivers/foo/foodriver.o] Error 1 make[1]: *** [_module_/home/myd/code/drivers/foo] Error 2 make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-24-generic' make: *** [all] Error 2
Googling for it gave solutions that required compiling the kernel from source. But I don't think that one needs to recompile the source in order to compile a new driver module, or is it so? moreover, I am a little skeptical about compiling the kernel lest it should break my system altogether.
Is there a way I can get around this problem and compile my driver module?
Other details:
"uname -a" gives "Linux mybox 2.6.32-24-generic #38-Ubuntu SMP Mon Jul 5 09:22:14 UTC 2010 i686 GNU/Linux"
In case I posted in the wrong forum, I apologize, and would appreciate if you could tell me the right forum to post in.
Please help.
Thanks in advance.
IRLast edited by MikeTbob; 07-29-2010 at 02:14 AM. Reason: Added Code tags
- 07-28-2010 #2Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
More info
In case the link in the post above does not work, here is the code (copy-pasted):
-----------------------------------------
-----------------------------------------Code:#include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */ static int __init hello_start(void) { printk(KERN_INFO "Loading hello module...\n"); printk(KERN_INFO "Hello world\n"); return 0; } static void __exit hello_end(void) { printk(KERN_INFO "Goodbye Mr.\n"); } module_init(hello_start); module_exit(hello_end);
The makefile is:
Any help please...Code:obj-m = foodriver.o KVERSION = 2.6.32-24-generic PWD = /home/myd/code/drivers/foo all: <tab>make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules clean: <tab>make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
Last edited by MikeTbob; 07-29-2010 at 02:14 AM. Reason: Added Code tags
- 07-28-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
Just an update:
The same code and Makefile work when compiled on Fedora 12. However, I NEED to do that on Ubuntu.
Please help.
Thanks,
IR
- 07-28-2010 #4
you should only post code inside code tags, so it is easier to read
that being said, F12 and ubuntu have different kernels, the API can be different, but what you are doing shouldn't have changed between the 2
are you sure you have the right package installed on ubuntu? you need like sudo apt-get install linux-headers-`uname -r`
- 07-28-2010 #5Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
Thanks coopstah13 for your reply. Will use code tags henceforth.
I do have headers for the kernel version I am running. I will anyway run the linux-header installer command as you suggested and post again if things still don't work.
- 07-29-2010 #6Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
Hi coopstah13,
I tried your suggestion. The headers already existed. This was the output of sudo apt-get install linux-headers-`uname -r`:
What else can I try?Code:linux-headers-2.6.32-24-generic is already the newest version. The following packages were automatically installed and are no longer required: libglib1.2ldbl plasma-dataengines-workspace kdepim-runtime libprocessui4 libtaskmanager4 libqimageblitz4 libkscreensaver5 libsolidcontrolifaces4 libgtk1.2 libswt-cairo-gtk-3.5-jni plasma-widgets-workspace mysql-client-core-5.1 libswt-gtk-3.5-jni liblog4j1.2-java libswt-mozilla-gtk-3.5-jni libplasma-geolocation-interface4 libcommons-cli-java mysql-server-core-5.1 libksgrd4 kdebase-workspace-bin libkworkspace4 libplasmagenericshell4 libkfontinst4 libkephal4 kdebase-workspace-data libgtk1.2-common ksysguardd libplasmaclock4 libweather-ion4 kdebase-workspace-kgreet-plugins libsolidcontrol4 akonadi-server libcommons-lang-java libswt-gnome-gtk-3.5-jni libswt-gtk-3.5-java libplasma-applet-system-monitor4 libprocesscore4 java-wrappers Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Thanks,
IR
- 08-12-2010 #7Just Joined!
- Join Date
- Jun 2010
- Posts
- 7
Maybe try Makefile like this:
Simple make command should work.Code:obj-m += foodriver.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


Reply With Quote
