Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Little Driver Module

Altera_Forum
Honored Contributor II
1,247 Views

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&#39; 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&#39; has incomplete type[c:/altera/../include/linux/pid.h]  

error: field `pid_list&#39; has incomplete type[c:/altera/../include/linux/pid.h]  

~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 

 

Does somebody have an idea what is going wrong? 

 

 

Bye, Lothar.
0 Kudos
11 Replies
Altera_Forum
Honored Contributor II
456 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hi Helmchen & all! 

 

I reduce the above example a little bit, to avoid unnecessary errors: 

 

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` 

 

 

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&#39; 

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&#39;. 

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&#39;. 

/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&#39;. 

make[2]: Failed to remake makefile `Rules.mak&#39;. 

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&#39;. 

make[2]: Failed to remake makefile `.config&#39;. 

MODPOST 

scripts/mod/modpost: not found 

make[2]: *** [__modpost] Error 127 

make[2]: Target `_modpost&#39; not remade because of errors. 

make[1]: *** [modules] Error 2 

make[1]: Target `_all&#39; 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&#39; 

make: *** [all] Error 2 

~~~~~~~~~~~~~~~~~~~~~~~ 

 

Have somebody an idea what is the reason for these errors? 

 

 

Bye, Lothar.
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hi Lothar 

 

you&#39;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 &#39;Create new make tage&#39;, the command line should look like 

ARCH=nios2nommu CROSS_COMPILE=nios2-elf- all 

but its just one way to do... 

 

c) about the modpost i don&#39;t know... maybe this error goes away, when you have done the changes above. 

 

Best Regards
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

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: 

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 

 

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: 

 

/cygdrive/c/../linux/sched.h:1174: error: `task_unmapped_base&#39; 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&#39;t a prototype 

/cygdrive/c/../linux/sched.h:1181: error: parse error before "pid" 

/cygdrive/c/../linux/sched.h:1181: warning: function declaration isn&#39;t a prototype 

/cygdrive/c/../linux/sched.h: in function `freeze_processes&#39;: 

/cygdrive/c/../linux/sched.h:1209: warning: implicit declaration of function `bug&#39; 

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&#39; isn&#39;t known 

{standard input}: assembler messages: 

{standard input}:359: error: symbol `seq&#39; is already defined 

{standard input}:407: error: symbol `sem_nsems&#39; is already defined 

{standard input}:428: error: symbol `lock&#39; is already defined 

{standard input}:1159: error: symbol `flags&#39; is already defined 

{standard input}:1504: error: symbol `files&#39; is already defined 

{standard input}:1696: error: symbol `blocks&#39; is already defined 

make[3]: *** [/cygdrive/c/entwicklung/nios/workspace3/hello_driver_linux/hello.o] error 1 

make[3]: target `__build&#39; not remade because of errors. 

make[2]: *** [_module_/cygdrive/c/entwicklung/nios/workspace3/hello_driver_linux] error 2 

make[2]: target `_all&#39; 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&#39; 

make[1]: *** [_all] error 2 

make: *** [all] error 2 

 

 

Do somebody have an idea how can I avoid these errors? 

 

 

Bye, Lothar.
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hi 

 

If you follow the whole thread you would see that the -o $@ is wrong 

 

Try this 

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 

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.
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

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: 

 

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/Linux_Kernel_full/build all:: $(MAKE) -C $(KERNELDIR) M=`pwd` O=$(BUILDDIR) modules endif 

 

Compiler output is: 

make -k all  

make: nothing to be done for `all&#39;. 

 

 

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&#39;s: 

/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_1.4.0 

 

2) Path to kernel I have compiled. It&#39;s: 

/cygdrive/c/Entwicklung/NIOS/workspace3/Linux_Kernel_full 

 

3) Path to driver sources: 

/cygdrive/c/Entwicklung/NIOS/workspace3/hello_driver_linux 

 

 

Bye, Lothar.
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hello! 

 

Ups! I&#39;ve forget a TAB-sign ahead the make command in Makefile. 

 

Now the compiler produce this: 

make -k all  

make -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&#39; 

no emulation specific options. 

building modules, stage 2. 

modpost 

scripts/mod/modpost: not found 

make[3]: *** [__modpost] error 127 

make[3]: target `_modpost&#39; 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&#39; 

make: *** [all] error 2 

 

The modpost.exe is in directory  

$(BUILDDIR)\scripts\mod 

 

I think it should be found there, but it&#39;s not working? 

 

 

Bye, Lothar.
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hi 

 

It seems that your &#39;stage 1&#39; 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
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hi ! 

 

I have convert module.symvers into UNIX format, but the result of building remains the same. 

 

I don&#39;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.
0 Kudos
Altera_Forum
Honored Contributor II
456 Views

Hi all! 

 

It works:-) 

 

After a new building of the kernel I tried to build the driver. 

The error message was switching from error 127 to 139. 

Therefore I converted module.symvers into UNIX format. 

I started the build again and it has produced a .ko file 

without any error. 

 

 

Thank you for helping, Lothar.
0 Kudos
Reply