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++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Hello world build error!

Altera_Forum
Honored Contributor II
1,474 Views

Hi all, 

When build the hello_world.c, I encount a error, Is any one can help me out? 

the hello_world.c as follows: 

#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"); 

and the problem as follows: 

$ nios2-linux-uclibc-gcc linux-2.6.x/drivers/misc/hello.c -o hello -elf2flt="-s 4000" In file included from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/sched.h:16,                 from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/module.h:9,                 from linux-2.6.x/drivers/misc/hello.c:6: /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/signal.h:2:2: warning:# warning "You should include <signal.h>. This time I will do it for you." In file included from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/sched.h:79,                 from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/module.h:9,                 from linux-2.6.x/drivers/misc/hello.c:6: /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/resource.h:2:2: warning:# warning "You should include <sys/resource.h>. This time I will do it for you." In file included from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/asm/cache.h:25,                 from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/cache.h:5,                 from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/module.h:10,                 from linux-2.6.x/drivers/misc/hello.c:6: /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/asm/nios.h:4:26: nios2_system.h: No such file or directory In file included from linux-2.6.x/drivers/misc/hello.c:6: /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/module.h:41: error: field `attr&#39; has incomplete type /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/../../../../nios2-linux-uclibc/sys-include/linux/module.h:49: error: field `kobj&#39; has incomplete type linux-2.6.x/drivers/misc/hello.c: In function `hello_init&#39;: linux-2.6.x/drivers/misc/hello.c:14: error: `KERN_ALERT&#39; undeclared (first use in this function) linux-2.6.x/drivers/misc/hello.c:14: error: (Each undeclared identifier is reported only once linux-2.6.x/drivers/misc/hello.c:14: error: for each function it appears in.) linux-2.6.x/drivers/misc/hello.c:14: error: syntax error before string constant linux-2.6.x/drivers/misc/hello.c: In function `hello_exit&#39;: linux-2.6.x/drivers/misc/hello.c:19: error: `KERN_ALERT&#39; undeclared (first use in this function) linux-2.6.x/drivers/misc/hello.c:19: error: syntax error before string constant 

 

It says the &#39;KERN_ALERT&#39; was not declared, but what try &#39;make&#39;, it has no problem.  

Is that it need include other files in hello_world.c? How to build executable file for nios independent? 

I hope anyone can help me out? ths!
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
616 Views

didn&#39;t you try 

make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- -C ~/uClinux-dist/linux-2.6.x M=`pwd` modules 

 

which you will need to compile device drivers  

 

instead of 

 

nios2-linux-uclibc-gcc linux-2.6.x/drivers/misc/hello.c -o hello -elf2flt="-s 4000" 

which suits for user programm. 

 

You will find detailed explanation in the kernel docs. 

 

hope this helps, but i&#39;m not a kernel crack 

maybe you take a look at the nioswiki for the module programming example. 

 

by the way let me ask you, what do you want to do? 

do you want to write a device driver or a user program.
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

 

--- Quote Start ---  

originally posted by helmchen@Feb 3 2007, 10:52 PM 

didn&#39;t you try 

make arch=nios2nommu cross_compile=nios2-linux-uclibc- -c ~/uclinux-dist/linux-2.6.x m=`pwd` modules 

 

which you will need to compile device drivers   

 

instead of 

 

nios2-linux-uclibc-gcc linux-2.6.x/drivers/misc/hello.c -o hello -elf2flt="-s 4000" 

which suits for user programm. 

 

you will find detailed explanation in the kernel docs. 

 

hope this helps, but i&#39;m not a kernel crack 

maybe you take a look at the nioswiki for the module programming example. 

 

by the way let me ask you, what do you want to do? 

do you want to write a device driver or a user program. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=21184)</div> 

--- Quote End ---  

 

hi Helmchen, 

thank you very much for your reply, I&#39;m porting uCLinux on my own NiosII board, and start develope programme according to hippo&#39;s post: 

http://forum.niosforum.com/forum/index.php?showtopic=3174 (http://forum.niosforum.com/forum/index.php?showtopic=3174

when come to 11 tips, I have tied code he provided: 

----------------- 

nios2-linux-uclibc-gcc hello.c -o hello -elf2flt cp hello ~/rootfs/bin 

Rebuild the kernel image for initramfs, boot nios2 uClinux, and run 

hello 

----------------- 

Here the &#39;hello.c&#39; is a user programme, I mistake it to a device driver, and use 

nios2-linux-uclibc-gcc linux-2.6.x/drivers/misc/hello.c -o hello -elf2flt="-s 4000" 

which is applied for user programme, so got the errors. 

Now I write a "hello world" user programme, and compiled successfully according the code. 

Thanks again! 

And I have a question: 

I have make a "hello_world" module which is a simple device driver, but I can only dynamic add it by "modprobe hello_world". 

Do you know how to add it with static method,namely add this module in when the kernel start?
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

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

--- Quote Start ---  

Do you know how to add it with static method,namely add this module in when the kernel start?[/b] 

--- Quote End ---  

 

 

Again please read about module programming in the nioswiki. 

 

nioswiki/module programming (http://nioswiki.jot.com/wikihome/operatingsystems/%c2%b5clinux/moduleprogramming)
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

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

--- Quote Start ---  

Do you know how to add it with static method,namely add this module in when the kernel start?[/b] 

--- Quote End ---  

 

 

Device Drivers --> 

Misc devices ---> 

<*> example hello module 

 

Press <Space> several times to select the mode of the driver, 

<M> is module 

<*> is static linked to kernel 

< > unselect
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

I want to know where i can find the hello module after the image is download into the DE2.Is it in the dir of /bin? but i can not find it.

0 Kudos
Altera_Forum
Honored Contributor II
616 Views

 

--- Quote Start ---  

originally posted by liuxiaoping@Mar 25 2007, 09:57 PM 

i want to know where i can find the hello module after the image is download into the de2.is it in the dir of /bin? but i can not find it. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22486) 

--- quote end ---  

 

--- Quote End ---  

 

All kernel modules will be in the /lib/modules/ <kernel version> tree. 

Don&#39;t mix up kernel modules with user apps.
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

To hippo: 

I am very sorry for my mistake,in fact,i did not find the module in the dir /lib,not /bin.In the dir of bin,i use the command ls,but there is only a file,i don&#39;t know why?
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

Make sure you have the hello.c in linux-2.6.x/drivers/misc, and you have updated Kconfig an Makefile in that dir. 

After "make" and "make linux images", in the uClinux-dist dir, 

please check if you have the hello.ko 

"tree linux-2.6.x/drivers/misc" 

"tree romfs/lib"  

 

Or you may check some other drivers or fs as modules, and find the modules of them.
0 Kudos
Reply