Hello, I have done device drivers for intel platform but I am running into errors while compiling a simple "hello world" driver for the mini2440 board (linux) Can someone please help me by showing a simple makefile and the corresponding make command? On my development platform (linux, i386), I have the linux-2.6.32.2-mini2440-20110413.tar.gz unpacked. I also have arm gcc toolkit in proper path. Thanks a lot for any help. Nagaraj
makefile for simple device driver
Did you read: Documentation/arm/README, Documentation/kbuild/makefiles.txt, Documentation/kbuild/kbuild.txt and so on?
Hi Juergen, Thank you for responding. Yes I did look into the Documentation files and am still missing something. I get the "Kernel configuration invalid" error, and also I think I am not correctly getting the arm linux's include. I have pasted the errors and my files below. I hope they are readable. Can you please help me overcome the problem? Thank you for your patience and help. [hello]$ make -C /lib/modules/arm9/linux-2.6.32.2/ M=`pwd` hello make: Entering directory `/lib/modules/arm9/linux-2.6.32.2' ERROR: Kernel configuration is invalid. include/linux/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it. arm-linux-gcc /home/pn/work/armdriver/hello/hello.c -o hello hello.c:5:27: error: /linux/kernel.h: No such file or directory hello.c:6:27: error: /linux/module.h: No such file or directory hello.c:7:27: error: /linux/device.h: No such file or directory hello.c:10: error: expected declaration specifiers or '...' before string constant hello.c:10: warning: data definition has no type or storage class hello.c: In function 'hello_init': hello.c:14: error: 'KERN_ALERT' undeclared (first use in this function) hello.c:14: error: (Each undeclared identifier is reported only once hello.c:14: error: for each function it appears in.) hello.c:14: error: expected ')' before string constant hello.c: In function 'hello_exit': hello.c:20: error: 'KERN_ALERT' undeclared (first use in this function) hello.c:20: error: expected ')' before string constant hello.c: At top level: hello.c:23: warning: data definition has no type or storage class hello.c:23: warning: parameter names (without types) in function declaration hello.c:24: warning: data definition has no type or storage class hello.c:24: warning: parameter names (without types) in function declaration make: *** [hello] Error 1 make: Leaving directory `/lib/modules/arm9/linux-2.6.32.2' Here is my two line makefile (trying to include the arm linux stuff): LINUXINCLUDE += -I/lib/modules/arm9/linux-2.6.32.2/include/ obj-m := hello.o And my hello.c code: #include </linux/kernel.h> #include </linux/module.h> #include </linux/device.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "Goodbye\n"); } module_init(hello_init); module_exit(hello_exit);
Hi Juergen, I read the modules.txt, too. I could not find anythign about the missing linux/autoconf.h The make file output message is clear - to run 'make oldconfig && make prepare" on the kernel src. I tried "make oldconfig". It asks a lot of questions, requires some knowledge to answer. Is this the only way to get the missing autoconf.h? Is there some help somewhere about this? I am afraid this is now general topic and less to do with friendlyarm! Will be grateful if some expert helps me get going! Thanks a lot. Nagaraj
Some more notes: the module you try to build can only be built against a configured and already built kernel tree. And, more important: this module can only be used with this built kernel! You can't use this module later on on a different kernel (sometimes it works, but most of the time it fails badly). a) get the sources of the currently running kernel on your Mini2440 b) get the configuration this kernel on your Mini2440 was built with c) build this kernel source tree d) run this kernel on your target (to check if its correct) e) build your module against this kernel source tree f) load this module on your target g) be happy ;-) Everything between the module and the running kernel must be in sync. IIRC also the compiler must be the same for the kernel and the module. That's why it is so important to work with the sources and not with binaries.
Hi Jeurgen, Your most recent posting is a mini tutorial for me. It all worked, all the way upto and including point (g) Thanks a lot for your help! Nagaraj