Forum Discussion
Altera_Forum
Honored Contributor
20 years agoLittle Driver Module
Hello!
I want to compile this little programm:#include <linux/module.h># include <linux/kernel.h># include <linux/init.h>
static int __init hello_init(void)
{
printk("----------->Hello, world\n");
return 0;
}
static void __exit hello_exit(void)
{
printk("------------>Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit); with that makefile: include Rules.mak
# ECLIPSE_WORKSPACE := ECLIPSE_WORKSPACE := /cygdrive/c/Entwicklung/NIOS/workspace3
KERNEL_PROJECT := Linux_Kernel_full
BUILDDIR := $(ECLIPSE_WORKSPACE)/$(KERNEL_PROJECT)/build/include
CFLAGS += -O0 -g -I$(BUILDDIR)
all: hello.exe hello.gdb But the compiler produce a lot of errors. Here are some of the first: ~~~~~~~~~~~~~~~~~~~~~~~~~~~ in inclusion c:/altera/../include/asm/siginfo.h:26:[c:/altera/../include/linux/signal.h] in inclusion c:/altera/../include/asm/div64.h:28:[c:/altera/../include/linux/jiffies.h] in inclusion c:/altera/../include/linux/sched.h:102:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:12:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:15:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:19:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:23:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:27:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:31:[c:/altera/../include/linux/module.h] in inclusion c:/altera/../include/linux/sched.h:32:[c:/altera/../include/linux/module.h] error: field `entry' has incomplete type[c:/altera/../include/linux/timer.h] in inclusion c:/altera/../include/linux/jiffies.h:386[c:/altera/../include/linux/sched.h] in inclusion c:/altera/../include/linux/jiffies.h:9:[c:/altera/../include/linux/sched.h] error: parse error before "wait_queue_head_t"[c:/altera/../include/linux/completion.h] in inclusion c:/altera/../include/linux/cpumask.h:78:[c:/altera/../include/linux/sched.h] in inclusion c:/altera/../include/linux/cpumask.h:81[c:/altera/../include/linux/sched.h] error: field `pid_chain' has incomplete type[c:/altera/../include/linux/pid.h] error: field `pid_list' has incomplete type[c:/altera/../include/linux/pid.h] ~~~~~~~~~~~~~~~~~~~~~~~~~~ Does somebody have an idea what is going wrong? Bye, Lothar.11 Replies
- Altera_Forum
Honored Contributor
Hi Lothar,
you nearly got it, you need to change it a little bit ifneq ($(KERNELRELEASE),)# kbuild part of makefile obj-m := driver.o else# Normal Makefile KERNELDIR := $(KERNEL_PLUGIN)/linux-2.6.x all:: $(MAKE) -C $(KERNELDIR) M=`pwd` endif KERNEL_PLUGIN is the installationpath of the linux distro Best Regards - Altera_Forum
Honored Contributor
Hi Helmchen & all!
I reduce the above example a little bit, to avoid unnecessary errors:
But there are still 2 errors: make -C /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x M=`pwd` make[1]: Entering directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x' Makefile:486: .config: No such file or directory Makefile:531: /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x/arch/i386/Makefile: No such file or directory make[1]: *** No rule to make target `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x/arch/i386/Makefile'. make[1]: Failed to remake makefile `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x/arch/i386/Makefile'. /cygdrive/c/Entwicklung/NIOS/workspace3/hello_driver_linux/Makefile:1: Rules.mak: No such file or directory make[2]: *** No rule to make target `Rules.mak'. make[2]: Failed to remake makefile `Rules.mak'. Building modules, stage 2. /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x/scripts/Makefile.modpost:38: .config: No such file or directory make[2]: *** No rule to make target `.config'. make[2]: Failed to remake makefile `.config'. MODPOST scripts/mod/modpost: not found make[2]: *** [__modpost] Error 127 make[2]: Target `_modpost' not remade because of errors. make[1]: *** [modules] Error 2 make[1]: Target `_all' not remade because of errors. make[1]: Leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x' make: *** [all] Error 2 ~~~~~~~~~~~~~~~~~~~~~~~ Have somebody an idea what is the reason for these errors? Bye, Lothar.include Rules.mak ECLIPSE_WORKSPACE := /cygdrive/c/Entwicklung/NIOS/workspace3 KERNEL_PROJECT := Linux_Kernel_full KERNEL_PLUGIN:= /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0 BUILDDIR := $(ECLIPSE_WORKSPACE)/$(KERNEL_PROJECT)/build/include KERNELDIR := $(KERNEL_PLUGIN)/linux-2.6.x CFLAGS += -O0 -g -I$(BUILDDIR) all: make -C $(KERNELDIR) M=`pwd` - Altera_Forum
Honored Contributor
Hi Lothar
you're almost there... a) you do not need rules.mak in your file http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif You are building for an i386 architecture. Look a bit closer at error log. there is something like <div class='quotetop'>QUOTE </div> --- Quote Start --- Makefile:531: /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x/arch/i386/Makefile[/b] --- Quote End --- You must tell the Kbuild-Sys that you want to build for Nios: When you are defining a make target with 'Create new make tage', the command line should look like
but its just one way to do... c) about the modpost i don't know... maybe this error goes away, when you have done the changes above. Best RegardsARCH=nios2nommu CROSS_COMPILE=nios2-elf- all - Altera_Forum
Honored Contributor
Hi all
I have the same problems. Have a look at the previous thread. Hope this helps makefile for simple linux device driver (http://www.niosforum.com/forum/index.php?showtopic=2411) Rual - Altera_Forum
Honored Contributor
Hi!
Thank you Rual. I followed your advice to look at thread makefile for simple linux device driver (http://www.niosforum.com/forum/index.php?showtopic=2411) And I change my makefile in this way:
I have set the variables ARCH := nios2nommu CROSS_COMPILE := nios2-elf- as enviroment variables. These all cause a lot of compiler errors, which are propably caused by path problems. I show you only the start and the end of all compiler errors:ifneq ($(KERNELRELEASE),)# kbuild part of makefile obj-m := hello.o else# Normal Makefile KERNEL_PLUGIN:= /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0 KERNELDIR := $(KERNEL_PLUGIN)/linux-2.6.x BUILDDIR := /cygdrive/c/Entwicklung/NIOS/workspace3/hello_driver_linux all:: $(MAKE) -C $(KERNELDIR) M=`pwd` O=$(BUILDDIR) -o $@ endif/cygdrive/c/../linux/sched.h:1174: error: `task_unmapped_base' undeclared (first use in this function)
/cygdrive/c/../linux/sched.h:1175: error: dereferencing pointer to incomplete type
/cygdrive/c/../linux/sched.h:1176: error: dereferencing pointer to incomplete type
/cygdrive/c/../linux/sched.h: at top level:
/cygdrive/c/../linux/sched.h:1180: error: parse error before "pid"
/cygdrive/c/../linux/sched.h:1180: warning: function declaration isn't a prototype
/cygdrive/c/../linux/sched.h:1181: error: parse error before "pid"
/cygdrive/c/../linux/sched.h:1181: warning: function declaration isn't a prototype
/cygdrive/c/../linux/sched.h: in function `freeze_processes':
/cygdrive/c/../linux/sched.h:1209: warning: implicit declaration of function `bug'
in file included from /cygdrive/c/../linux/module.h:13,
from /cygdrive/c/entwicklung/nios/workspace3/hello_driver_linux/hello.c:1:
/cygdrive/c/../linux/stat.h:6:22: asm/stat.h: no such file or directory
in file included from /cygdrive/c/../linux/module.h:13,
from /cygdrive/c/entwicklung/nios/workspace3/hello_driver_linux/hello.c:1:
.............
.............
.............
/cygdrive/c/../linux/stat.h:70: error: storage size of `ctime' isn't known
{standard input}: assembler messages:
{standard input}:359: error: symbol `seq' is already defined
{standard input}:407: error: symbol `sem_nsems' is already defined
{standard input}:428: error: symbol `lock' is already defined
{standard input}:1159: error: symbol `flags' is already defined
{standard input}:1504: error: symbol `files' is already defined
{standard input}:1696: error: symbol `blocks' is already defined
make[3]: *** [/cygdrive/c/entwicklung/nios/workspace3/hello_driver_linux/hello.o] error 1
make[3]: target `__build' not remade because of errors.
make[2]: *** [_module_/cygdrive/c/entwicklung/nios/workspace3/hello_driver_linux] error 2
make[2]: target `_all' not remade because of errors.
make[1]: leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x'
make[1]: *** [_all] error 2
make: *** [all] error 2
Do somebody have an idea how can I avoid these errors? Bye, Lothar.
- Altera_Forum
Honored Contributor
Hi
If you follow the whole thread you would see that the -o $@ is wrong Try this
You should note that BUILDDIR should be the (COMPILED_LINUX_KERNEL)/build directory. Also insert the ARCH and CROSS_COMPILE variables in the IDE make_target make field.ifneq ($(KERNELRELEASE),)# kbuild part of makefile obj-m := hello.o else# Normal Makefile KERNEL_PLUGIN:= /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0 KERNELDIR := $(KERNEL_PLUGIN)/linux-2.6.x BUILDDIR := /cygdrive/c/Entwicklung/NIOS/workspace3/hello_driver_linux all:: $(MAKE) -C $(KERNELDIR) M=`pwd` O=$(BUILDDIR) modules endif - Altera_Forum
Honored Contributor
Hi Rual!
Now I have try to follow strictly the threat makefile for simple linux device driver (http://www.niosforum.com/forum/index.php?showtopic=2411) My result is this makefile:
Compiler output is: make -k allifneq ($(KERNELRELEASE),)# kbuild part of makefile obj-m := hello.o else# Normal Makefile KERNEL_PLUGIN:= /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0 KERNELDIR := $(KERNEL_PLUGIN)/linux-2.6.x BUILDDIR := /cygdrive/c/Entwicklung/NIOS/workspace3/Linux_Kernel_full/build all:: $(MAKE) -C $(KERNELDIR) M=`pwd` O=$(BUILDDIR) modules endifmake: nothing to be done for `all'.
And no build output was generated. Could it be that something is going wrong with pathes. I have three pathes belonging to the driver I want to build: 1) Path to kernel sources, provided by microtronix. It's: /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0 2) Path to kernel I have compiled. It's: /cygdrive/c/Entwicklung/NIOS/workspace3/Linux_Kernel_full 3) Path to driver sources: /cygdrive/c/Entwicklung/NIOS/workspace3/hello_driver_linux Bye, Lothar.
- Altera_Forum
Honored Contributor
Hello!
Ups! I've forget a TAB-sign ahead the make command in Makefile. Now the compiler produce this: make -k allmake -c /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x m=`pwd` o=/cygdrive/c/entwicklung/nios/workspace3/linux_kernel_full/build modules
make[1]: entering directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x'
no emulation specific options.
building modules, stage 2.
modpost
scripts/mod/modpost: not found
make[3]: *** [__modpost] error 127
make[3]: target `_modpost' not remade because of errors.
make[2]: *** [modules] error 2
make[1]: *** [modules] error 2
make[1]: leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x'
make: *** [all] error 2 The modpost.exe is in directory $(BUILDDIR)\scripts\mod I think it should be found there, but it's not working? Bye, Lothar.
- Altera_Forum
Honored Contributor
Hi
It seems that your 'stage 1' compilation is now working fine. After you compiled it like this, the modpost sh%^ is something to do with the spaces, tabs or linefeeds in the modules.symvers file generated in your COMPILED_KERNEL/build dir. Now open the IDE shell and browse to that dir. Then type in something like blabla/../bla >dos2unix modules.symvers Then compile the driver again. This is a lot of shlep, I know. Hopefully your outputs will be generated. Good luck Rual - Altera_Forum
Honored Contributor
Hi !
I have convert module.symvers into UNIX format, but the result of building remains the same. I don't think that module.symvers can cause such a build error. File module.symvers works fine when I build the kernel. As we can see in threath makefile for simple linux device driver (http://www.niosforum.com/forum/index.php?showtopic=2411) the error with wrong file format has number 127 and not not 139. This is another hint, that the problems of building are not caused by missing UNIX format of files. Bye, Lothar.