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++
12747 Discussions

Kernel development on Nios Linux 2.6 distribution

Altera_Forum
Honored Contributor II
3,923 Views

The Nios II Linux 2.6 distribution is not really biased for kernel development, but since this is all what I have, what way you suggest I should develop my drivers? 

 

I understood importing the source files into a kernel project was good just for debugging the kernel, so that you actually see where you are going.  

So any changes should be made directly to the kernel directory in the Eclipse plug-in directory. Am I right? 

 

Okay, I can do the changes there, but how can I get them into the IDE reasonably? There's no "open file" option in the IDE! 

If I develop my driver as a module, could I just use the Linux application project as a basis and just fix the makefile so that it will be compiled as a module? 

Will there be a problem with the kernel include files? 

 

Thanks for any ideas in advance! 

 

 

-Tervis
0 Kudos
21 Replies
Altera_Forum
Honored Contributor II
1,175 Views

Hey come on! 

 

Am I the only one wanting to develop kernel drivers with this package. I seriously doubt that... 

Gimme some input here, please... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/laugh.gif  

 

 

-Tervis
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

This message will describe building a hello_world driver for the kernel. The driver will be listed as a miscellaneous driver inside the kernel configuration tool. 

 

(1) Create the code for the driver (hello_world.c): 

 

#include <linux/init.h># include <linux/module.h># include <linux/kernel.h> static int hello_init(void) {     printk (KERN_ALERT "Hello, world!\n");     return 0; } static void hello_exit (void) {     printk (KERN_ALERT "Goodbye, cruel world\n"); } module_init (hello_init); module_exit (hello_exit); MODULE_LICENSE("Dual BSD/GPL"); 

(2) Create the Makefile for the driver: 

ifneq ($(KERNELRELEASE),) # This is the section of the Makefile that builds the module inside the kernel obj-$(CONFIG_HELLO_WORLD) := hello_world.o else # This section is for building the module outside of the source # $(ECLIPSE_WORKSPACE) is assumed to be defined externally by the environment # please reference the articles on http://www.lwn.net regarding# kernel module development for more information about this Makefile KDIR := $(KERNEL_PLUGIN)/linux-2.6.x KERNEL_PROJECT := eval_kit_0 BUILDDIR := $(ECLIPSE_WORKSPACE)/$(KERNEL_PROJECT)/build PWD := $(shell pwd) default:     $(MAKE) -C $(KDIR) O=$(BUILDDIR) SUBDIRS=$(PWD) modules endif 

(3) Copy the two files into the source tree using the following few commands: 

 

cd <wherever the above files live> mkdir $(KERNEL_PLUGIN)/linux-2.6.x/misc/hello_world cp * $(KERNEL_PLUGIN)/linux-2.6.x/drivers/misc/hello_world 

(4) Update the Makefile and Kconfig file in the $(KERNEL_PLUGIN)/linux-2.6.x/drivers/misc directory... 

## Makefile for misc devices that really don&#39;t fit anywhere else.# obj- := misc.o   # Dummy rule to force built-in.o to be made obj-$(CONFIG_IBM_ASM)    += ibmasm/ # add the following line obj-$(CONFIG_HELLO_WORLD) += hello_world/ 

## Misc strange devices# menu "Misc devices" config IBM_ASM     tristate "Device driver for IBM RSA service processor"     depends on X86     default n     ---help---   This option enables device driver support for in-band access to the   IBM RSA (Condor) service processor in eServer xSeries systems.   The ibmasm device driver allows user space application to access   ASM (Advanced Systems Management) functions on the service   processor. The driver is meant to be used in conjunction with   a user space API.   The ibmasm driver also enables the OS to use the UART on the          service processor board as a regular serial port.     If unsure, say N. # add the following few lines config HELLO_WORLD     tristate "Hello_world example"     default n endmenu 

 

After saving all the modified files, you can now configure a kernel with the above driver. It is recommended that the driver be compiled into the kernel for testing purposes since that should help with the debugging effort. 

 

The kernel option will appear in Device Drivers -> Miscellaneous -> Hello_world example. 

 

Once you have configured, built, and uploaded your kernel, the kernel should start and display: "Hello, World!" while it is starting up. 

 

Much of the above code was taken from LWN.net&#39;s Device driver series of articles. 

 

Hope this helps... 

 

Ken. 

BTW, debugging is discussed within the reference manual I believe... I may post some additional instructions up here later on if people have trouble with debugging the kernel.
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Is it possible to develop a kernel driver as an independant module ? This module will be dynamically linked in the kernel with insmod command. 

 

I tried to develop such a module, like I used to do under "standard" Linux (Red Hat or Montavista), but I get several warnings on compiling "linux/module.h" and "linux/kernel.h". Is there other defines to add that __KERNEL__ and MODULE ? Should I use the standard C library for kernel development ?
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

Is it possible to develop a kernel driver as an independant module ? This module will be dynamically linked in the kernel with insmod command.[/b] 

--- Quote End ---  

 

 

Yep. You&#39;ll need to use insmod from busybox to load in the module. I&#39;ve done it a number of times using a very simple hello_world example driver. 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

Is there other defines to add that __KERNEL__ and MODULE ?  Should I use the standard C library for kernel development ?[/b] 

--- Quote End ---  

 

 

That I&#39;m not sure of, my driver development skills aren&#39;t very strong. I would recommend the following two sites for more information. 

 

linux device drivers, 2nd edition: online book (http://www.xml.com/ldd/chapter/book/

lwn: porting device drivers to the 2.6 kernel (http://lwn.net/articles/driver-porting/

 

I found that most of the information from both sources are quite applicable. 

 

Hope this helps...
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Previous answer is not enough to build a module independantly from Kernel. My goal is to have my source files on a separate directory (which is handled by a Software Configuration Manager, here ClearCase) with a Makefile to generate the .o module file. 

 

I try to get back the compilation options from the .xxx.o.cmd file in kernel/build/drivers directory. I can now compile files and generate a module without any warning nor error. But this .o file is not recognized by insmod : it gives the following error message :  

 

No module found in object  

insmod: cannot insert "testModule_mod.o": Invalid module format (-1): Exec format error 

 

Here is the Makefile (a little bit ... complicated !). With this Makefile, I tried to re-compile one Kernel driver, and I&#39;m very surprise to find an object with a different size (124kb instead of 126kb) : I surely made a mistake, but I can&#39;t see where (no errors, no warning... but a little small difference !). 

 

 

all: testModule_mod.o testModule_mod.o: testModule.o     nios2-elf-ld  -mnios2elf  -r -o testModule_mod.o testModule.o testModule.o: testModule.c Makefile     nios2-elf-gcc -nostdinc -Wp,-MD,.testModule.o.d -iwithprefix include -D__KERNEL__ -Iinclude -Iinclude2 -I/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/include -I/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/ -I$(LIBMYKERNEL) -I$(LIBKERNEL) -D__KERNEL__ -I/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/include -Iinclude -I/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/include2 -Iinclude2  -I/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/include -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -DNO_MM -pipe -D__linux__ -D__ELF__ -DNO_TEXT_SECTIONS -fno-builtin -O2 -g -G 0 -DUTS_SYSNAME=\"uClinux\"  -I/cygdrive/c/altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc-lib/nios2-elf/3.3.3/include -O2 -fomit-frame-pointer  -DKBUILD_BASENAME=testModule  -DMODULE -c -o testModule.o testModule.c
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

That&#39;s an extremely complicated makefile... have you tried using the Makefile I provided in this thread? It does allow for building outside of the kernel tree. As a bonus, it also pulls in all the necessary rules for building the module properly from the original kernel source instead of requiring you to specify the rules manually. 

 

Give it a try, and post any errors that you get when you try running "make". It worked like a charm when I did it. 

 

In fact, here&#39;s the Makefile tailored to your situation: 

 

CONFIG_TEST_MOD=m ifneq ($(KERNELRELEASE),) # This is the section of the Makefile that builds the module inside the kernel obj-$(CONFIG_TEST_MOD) := testModule_mod.o else # This section is for building the module outside of the source# $(ECLIPSE_WORKSPACE) is assumed to be defined externally by the environment # please reference the articles on http://www.lwn.net regarding# kernel module development for more information about this Makefile KDIR := $(KERNEL_PLUGIN)/linux-2.6.x $(error You need to specify the kernel project that this module is being built for before this will work!)# delete the above line after you have modified the variable below to its proper setting KERNEL_PROJECT := your_kernel_project BUILDDIR := $(ECLIPSE_WORKSPACE)/$(KERNEL_PROJECT)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) O=$(BUILDDIR) SUBDIRS=$(PWD) modules endif
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

I&#39;m sorry, but I still have a lot of errors with your Makefile. I think the basic environment information is missing... 

 

Here are the error messages : (invoked directly from NIOS II-IDE, Build project option) 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

make -k default  

make -C /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x O=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/Kernel_DemoBoard_LAN/build SUBDIRS=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/testModule modules 

make[1]: Entering directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39; 

/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/Makefile:421: /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/arch/i386/Makefile: No such file or directory 

gcc: not found 

make[2]: *** No rule to make target `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/arch/i386/Makefile&#39;. 

make[2]: Failed to remake makefile `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/arch/i386/Makefile&#39;. 

gcc: not found 

  Using /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x as source for kernel 

gcc: not found 

*** Warning: Overriding SUBDIRS on the command line can cause 

***          inconsistencies 

gcc: not found 

  HOSTCC  scripts/basic/fixdep 

gcc: not found 

make[3]: *** [scripts/basic/fixdep] Error 127 

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

make[2]: *** [scripts_basic] Error 2 

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

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

make[1]: Leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39; 

make: *** [default] Error 2[/b] 

--- Quote End ---  

 

It appears that architecture information is missing, as Cross-compiler. So I tried to add &#39;ARCH=nios2nommu CROSS_COMPILE=nios2-elf-&#39; in $(MAKE) command. Result is better, but there is still problems : 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

make -k default  

make -C /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x ARCH=nios2nommu CROSS_COMPILE=nios2-elf- O=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/Kernel_DemoBoard_LAN/build SUBDIRS=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/testModule modules 

make[1]: Entering directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39; 

  Using /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x as source for kernel 

*** Warning: Overriding SUBDIRS on the command line can cause 

***          inconsistencies 

  HOSTCC  scripts/basic/fixdep 

gcc: not found 

make[3]: *** [scripts/basic/fixdep] Error 127 

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

make[2]: *** [scripts_basic] Error 2 

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

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

make: *** [default] Error 2 

make[1]: Leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39;[/b] 

--- Quote End ---  

 

 

Don&#39;t you have such errors ?
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Ah... I see. I forgot to mention that I meant for you to use the Makefile from Nios II SDK shell. There isn&#39;t an appropriate project type within the Nios II IDE for module/driver development yet. 

 

The Nios II SDK shell will contain all the correct environment variables that you need. It will also contain a correct PATH setting. 

 

Give it another shot through the Nios II SDK Shell and let me know how it goes...
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

OK, it&#39;s perfect ! I&#39;m sorry for so many exchanges for a so easy conclusion ! 

 

Hope it may help other guys !
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Hi, 

 

To continue on this same subject, I just dowloaded the new release 1.3 and I try to compile my driver, as a module. 

 

It doesn&#39;t compile any more : the error is "cannot find .config file". 

 

It seems to look for this file in the "plugins" kernel directory instead of my kernel directory. 

 

Is there something to change in the Makefile ? 

 

 

CONFIG_TEST_MOD=m ifneq ($(KERNELRELEASE),) # This is the section of the Makefile that builds the module inside the kernel obj-$(CONFIG_TEST_MOD) := JGXEOE.o else # This section is for building the module outside of the source# $(ECLIPSE_WORKSPACE) is assumed to be defined externally by the environment # please reference the articles on http://www.lwn.net regarding# kernel module development for more information about this Makefile KERNEL_PLUGIN := /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5 ECLIPSE_WORKSPACE := /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace KDIR := $(KERNEL_PLUGIN)/linux-2.6.x KERNEL_PROJECT := Kernel_MUX BUILDDIR := $(ECLIPSE_WORKSPACE)/$(KERNEL_PROJECT)/build PWD := $(shell pwd) default:     $(MAKE) -C $(KDIR) O=$(BUILDDIR) SUBDIRS=$(PWD) modules endif
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Sorry, the error was in my Makefile (a blank space in my Kernel name). 

 

However, I still have a problem coming from MODPOST : 

 

$ make make -C /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x O=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/KERNEL_MUX2/build SUBDIRS=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/jgxeoe_driver modules make: Entering directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39;  no emulation specific options.  CC  /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/jgxeoe_driver/JGXEOE.o /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/jgxeoe_driver/JGXEOE.c:51: warning: function declaration isn&#39;t a prototype … /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/jgxeoe_driver/.JGXEOE.o.d: done.  Building modules, stage 2.  MODPOST Signal 11 make: *** Error 139 make: *** Error 2 make: *** Error 2 make: Leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39; make: *** Error 2
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

I was talking with Marc the other day and I sent him an e-mail that I was hoping to get to you. 

 

He sent me some additional info and I noticed that modpost was attempting to use the vmlinux file as input which isn&#39;t how the Makefile/modpost is supposed to work. Can you post or send me your Makefile as well as a directory listing of where you&#39;re compiling your module? 

 

Just so you know, I was able to compile a hello_world module using the same instructions that I posted before under the 1.3 distro so I&#39;m fairly confident it works. Let&#39;s try to get you up and running.
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

omr22, 

 

We just encountered the same problem you are seeing with modpost: 

 

Building modules, stage 2. 

MODPOST 

Signal 11 

make[3]: *** [__modpost] Error 139 

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

 

After much debugging, we finally tracked it down to the Modules.symvers file (which is generated when the kernel is compiled) has DOS line endings instead of unix. The read_dump() function in modpost.c is not properly parsing the symbols read in from this file which is causing the error you&#39;re seeing. 

 

If you run dos2unix on Modules.symvers to convert it to a unix text file before building your module it should build without error.  

 

When you compile your kernel, if you add the V=1 option to the make command you&#39;ll see much more information about the commands which are run. You should see a call to scripts/mod/modpost which has the Modules.symvers file as one of it&#39;s inputs. 

 

 

 

Even though we&#39;ve apparently gotten the module to build without error; we&#39;re still having problems getting the module to load using busybox insmod:  

 

 

# insmod /modules/hello-1.ko 

insmod: cannot insert `/modules/hello-1.ko&#39;: Unknown symbol in module (-1): No such file or directory 

 

When I run it on the console I see additional error messages that indicate that the unresolved symbol is &#39;printk&#39;. 

 

 

Has anyone else encountered this problem? 

 

Thanks, 

Terry
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Hello, 

 

I tried to build my kernel module hello.c as described in this contribution, using Makefile specified here. But make command executed from NIOSII shell returns following errors and, I understand that it needs appropriate ptf file, but I dont know what to do... 

 

$ make make -C /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2l inux.kernel_0.1.5/linux-2.6.x O=/cygdrive/c/altera/kits/nios2/bin/eclipse/worksp ace/kernel_mod/build SUBDIRS=/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace /kernel_mod modules make: Entering directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/c om.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39; /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.ker nel_0.1.5/linux-2.6.x/Makefile:461: .config: No such file or directory  no emulation specific options. /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.ker nel_0.1.5/linux-2.6.x/arch/nios2nommu/Makefile:124: *** Run "make hwselect SYSPT F=<system.ptf>" first.  Stop. make: *** Error 2 make: Leaving directory `/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/co m.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x&#39; make: *** Error 2 /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/kernel_mod $ 

 

I hope someone can help, 

thank you, 

Jan
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

hello, 

 

second call http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

I still did not solved - can anyone help me with the problem described in the text above? 

 

thanks, 

Jan
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

In the same directory, run the following command (let&#39;s assume the ptf file from the core is c:/work/project1/linux.ptf): 

$ make hwselect SYSPTF=/cygdrive/c/work/project1/linux.ptf 

 

then you will be able to build the kernel.
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

hi wentao, 

Problem still not solved, I tried as you wrote and this error occured (my project directory is kernel_mod): 

 

/cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/kernel_mod $ make hwselect SYSPTF=/cygdrive/c/altera/kits/nios2/examples/ver ilog/niosII_cyclone_1c20/linux/linux_1c20.ptf make: *** No rule to make target `hwselect&#39;.  Stop. /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace/kernel_mod $ 

 

I also tried to run this command in ...../linux-2.6.x/arch/nios2nomu dir, which contains Makefile, which produced the error with "hwselect" and I got another error: 

 

/cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.ker nel_0.1.5/linux-2.6.x/arch/nios2nommu $ make hwselect SYSPTF=/cygdrive/c/altera/kits/nios2/examples/ver ilog/niosII_cyclone_1c20/linux/linux_1c20.ptf gcc: No input files mkdir -p /arch/nios2nommu/ Can&#39;t open perl script "/arch/nios2nommu/scripts/hwselect.pl": No such file or d irectory make: *** Error 2 /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.ker nel_0.1.5/linux-2.6.x/arch/nios2nommu $ 

 

 

it is clear to me, that I need to compile all together, but I dont know where or how to specify appropriate PTF and it also the mystery for me, why another users did not received this error... only for completion - I use nios2linux_1.3, 

 

with regards 

jan
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

Hi jan, 

 

I guess the command line "make hwselect ..." can be used only when you want to build kernel directly in the source tree. I will check this with Ken when he is back from vacation tomorrow. I am not using eclipse and able to run it directly from the root directory of the kernel source. 

 

Regards, 

wentao
0 Kudos
Altera_Forum
Honored Contributor II
1,175 Views

 

--- Quote Start ---  

originally posted by ken@Nov 26 2004, 09:37 AM 

that&#39;s an extremely complicated makefile... have you tried using the makefile i provided in this thread?  it does allow for building outside of the kernel tree.  as a bonus, it also pulls in all the necessary rules for building the module properly from the original kernel source instead of requiring you to specify the rules manually. 

 

give it a try, and post any errors that you get when you try running "make".  it worked like a charm when i did it. 

 

in fact, here&#39;s the makefile tailored to your situation: 

 

config_test_mod=m ifneq ($(kernelrelease),) # this is the section of the makefile that builds the module inside the kernel obj-$(config_test_mod) := testmodule_mod.o else # this section is for building the module outside of the source# $(eclipse_workspace) is assumed to be defined externally by the environment # please reference the articles on http://www.lwn.net regarding# kernel module development for more information about this makefile kdir := $(kernel_plugin)/linux-2.6.x $(error you need to specify the kernel project that this module is being built for before this will work!)# delete the above line after you have modified the variable below to its proper setting kernel_project := your_kernel_project builddir := $(eclipse_workspace)/$(kernel_project)/build pwd := $(shell pwd) default: $(make) -c $(kdir) o=$(builddir) subdirs=$(pwd) modules endif 

--- Quote End ---  

 

Hello, 

 

I used the Makefile you provided to compile my own simple Hello World kernel module. I want to build up a more sophisticated driver by adding calls to the Nios II HAL, but I can&#39;t get the module to compile whenever I include a HAL header file. 

 

For instance, adding  

 

#include "alt_types.h" 

 

to  

 

#include <stdio.h> int main() {    printf("Hello World\n");    return 0; } 

 

does not compile. 

 

Adding the proper directories to the include path using the Nios IDE does not fix the problem. Since we compile the kernel module using the Nios SDK Shell, adding the path in the IDE doesn&#39;t help, I suspect. 

 

I&#39;d like to add  

 

-I<HAL directories> 

 

to the Makefile you provided, but I&#39;m not sure how to do it in a clean way (ie. without modifying %eclipse_plugins%/com.microtronix.nios2linux.kernel_0.1.5/linux-2.6.x/Makefile).  

 

Summarizing, I would like to create a kernel module that calls HAL functions. Please explain how this can be done http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

Thank you, 

jwistead.
0 Kudos
Altera_Forum
Honored Contributor II
1,119 Views

Hello, 

 

I am still having this problem, and I&#39;ve tried *everything* I can think of to fix it myself. Please let me know if I can provide any more information to help solve it. 

 

Thank you, 

jwistead.
0 Kudos
Reply