LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2010, 11:41 PM   #1
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Rep: Reputation: 0
needed to compile my first kernel program


Please Help needed to compile my first kernel program

I have compile & install new kernel 2.6.32.3 on path: /root/linux2.6.32.3/
I have written small program [shown below] at path: /root/abc/

I already compile & install kernel 2.6.32.3 on fedora 10 machine & check /boot/grub/menu1.st entry it is there.

My program giving an error when I "make"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

uname: extra operand `.r'
Try `uname --help' for more information.
uname: extra operand `.r'
Try `uname --help' for more information.
make: Nothing to be done for `all'.


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

My Kernel Program

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
* hello.1.c . The simplest kernel module.
*/
#include </root/linux-2.6.32.3/include/linux/module.h> /* Needed by all modules */
#include </root/linux-2.6.32.3/include/linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Makefile look like

obj.m += hello.1.o
all:
make .C /lib/modules/$(shell uname .r)/build M=$(PWD) modules
clean:
make .C /lib/modules/$(shell uname .r)/build M=$(PWD) clean

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++~
myemail id : rachilmeth@googlemail.com
~
 
Old 01-15-2010, 12:00 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,672
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
1. Have u inserted tabs in your make file, check it twice because it is required !

2. "shell uname -r" NOT "shell uname .r" in your makefile

FOR MODIFICATIONS IN U R makefile SEE BELOW

Code:
obj-m += moduleName.o

all:
<TAB>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
<TAB>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Last edited by TheIndependentAquarius; 01-15-2010 at 12:15 AM.
 
Old 01-15-2010, 12:31 AM   #3
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
hello@anishakau
its working when i replace it, but no .ko file is created ..
the file which i got are ...
-rw-r--r-- 1 root root 0 Module.symvers
-rw-r--r-- 1 root root 0 modules.order
-rw-r--r-- 1 root root 291 Module.markers

thanks ..

Is this way u r sayn.

obj.m += hello-1.o [module name]
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
 
Old 01-15-2010, 12:36 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,672
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
I tried the program right now on my terminal, its working fine, and generating a .ko too.

Here's my kernel.c
Code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
	printk("Hello world 1.\n");
	return 0;
}

void cleanup_module(void)
{
	printk("Goodbye world 1.\n");
}
Here's the Makefile
Code:
obj-m += kernel.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
I need root's permission to do make !!

AND THIS WORKS VERY FINE !!

Last edited by TheIndependentAquarius; 01-15-2010 at 04:36 AM.
 
Old 01-15-2010, 04:08 AM   #5
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Can you please tell me which are good links and books name to refer this ..compile,programs,degugging related

Last edited by rachilmeth; 01-15-2010 at 04:23 AM. Reason: compiled
 
Old 01-15-2010, 04:10 AM   #6
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Can you please tell me which are good links and books name to refer this ..compile,programs,degugging related
 
Old 01-15-2010, 04:18 AM   #7
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,672
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
OS: OpenSuse 11.2
Gcc version: 4.4.1

Have u re-compiled your kernel ?

Some geek may be able to tell you about the uname -r command giving the old kernel version number !

What distribution and gcc version u are using ? Is it very old ?

Last edited by TheIndependentAquarius; 01-15-2010 at 04:55 AM.
 
Old 01-15-2010, 04:37 AM   #8
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
yeah I download latest kernel and recompiled using make menuconfig,make,make modules, make modules_install,make install..after that reboot..
uname -r given me myold linux version , not latest one ...
but while creating make mention the path of where my kernel present as given above in my first post.
 
Old 01-15-2010, 04:38 AM   #9
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
gcc version is 4.3.2
 
Old 01-15-2010, 04:40 AM   #10
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,672
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
May be that's what (kernel recompilation) is creating the problem:

Have a look here may be you'll get something out of it!

http://www.linuxquestions.org/questi...ersion-363398/

http://www.linuxquestions.org/questi...ersion-394417/

Last edited by TheIndependentAquarius; 01-15-2010 at 05:03 AM. Reason: added one more link
 
Old 01-15-2010, 04:53 AM   #11
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
Are you sure that your kernel is added to your grub list?
If so, are you sure to select the good grub (or lilo) entry? Not sure that the new entry is the default one...
By the way, downloading and building a new kernel just to build a driver is not appropriate. Just install the dev package for your current kernel through your package manager and build the driver you want, then you can test the freshly built driver without rebooting, just by insmod'ing it. I'm saying that mainly because it sounds like you're a newby and then you could easily destroy your system (not really destroyed, but a pain for a noob to fix) if you make any error while building / installing the new kernel.
If you want to experiment with kernel, here's a good starting point.
 
Old 01-15-2010, 05:00 AM   #12
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
thanks alot @ anisha
Can I work with my old kernel ..or i need to install new kernel to work for kernel prgoramming ?
 
Old 01-15-2010, 05:03 AM   #13
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
@jf.argentino

grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=1
timeout=0
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.32.3)
root (hd0,0)
kernel /boot/vmlinuz-2.6.32.3 ro root=UUID=21d34cba-e758-4a3d-8f2f-e98988868a68 rhgb quiet
initrd /boot/initrd-2.6.32.3.img
title Fedora (2.6.27.5-117.fc10.i686)
root (hd0,0)
kernel /boot/vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=21d34cba-e758-4a3d-8f2f-e98988868a68 rhgb quiet
initrd /boot/initrd-2.6.27.5-117.fc10.i686.img
 
Old 01-15-2010, 05:06 AM   #14
rachilmeth
LQ Newbie
 
Registered: Jan 2010
Posts: 19

Original Poster
Rep: Reputation: 0
yeah i m refering these book

device driver - link u posted
robert love linux kernel develpment.

thanks
 
Old 01-15-2010, 05:08 AM   #15
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,672
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Quote:
Originally Posted by rachilmeth
Can I work with my old kernel ..or i need to install new kernel to work for kernel prgoramming ?
U have deleted the information in your previous posts, now I am not able to see your old kernel version number ???
 
  


Reply

Tags
kernel, module


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to compile basic hello.c kernel program Suse Linux 9.3 pat_and_cami Programming 2 02-25-2006 02:13 PM
Kernel compile tips needed Tim Johnson Slackware 6 09-08-2005 06:30 PM
what ports needed to compile kernel? joroxx *BSD 13 12-01-2004 09:58 PM
Special things needed to compile a program? thw Linux - Newbie 4 03-27-2004 04:43 PM
how much space needed to compile a kernel? e1000 Linux - General 1 12-22-2003 04:17 PM


All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration