Fedora Linux Support Community & Resources Center
  #1  
Old 8th January 2008, 09:51 AM
muks Offline
Registered User
 
Join Date: Jan 2008
Location: Delhi, India
Age: 30
Posts: 25
Hello World Kernel Module

Hey i(Fedora Newbie) have Fedora 7 (Kernel: 2.6.23.12-52.fc7). I am following book titled " The Linux Kernel Module Programming Guide". I tried to compile the Hello World Kernel Module and got an error. Please go through the source code & error and let me know where i m wrong.

Source Code:
------------------
Code:
[root@localhost 02-HelloWorld]# cat hello-1.c 
#include <linux/module.h>
#include <linux/kernel.h>

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

void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
[root@localhost 02-HelloWorld]#
Makefile
----------
Code:
[root@localhost 02-HelloWorld]# cat Makefile 
obj-m += hello-1.c

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

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
[root@localhost 02-HelloWorld]#
Error
------
Code:
[root@localhost 02-HelloWorld]# make
make -C /lib/modules/2.6.23.12-52.fc7/build M=/home/mukul/Desktop/lkmpg-examples/02-HelloWorld modules
make[1]: Entering directory `/usr/src/kernels/2.6.23.12-52.fc7-i686'
scripts/Makefile.build:223: target `/home/mukul/Desktop/lkmpg-examples/02-HelloWorld/hello-1.c' doesn't match the target pattern
  Building modules, stage 2.
  MODPOST 0 modules
make[1]: Leaving directory `/usr/src/kernels/2.6.23.12-52.fc7-i686'
[root@localhost 02-HelloWorld]#
Reply With Quote
  #2  
Old 8th January 2008, 11:00 AM
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,905
This
Quote:
obj-m += hello-1.c
should be this
Quote:
obj-m += hello-1.o
Reply With Quote
  #3  
Old 8th January 2008, 11:15 AM
muks Offline
Registered User
 
Join Date: Jan 2008
Location: Delhi, India
Age: 30
Posts: 25
Quote:
should be this

Code:
obj-m += hello-1.o
Thanks a lot. Couldn't c that print mistake.

Can you also tell me where i can read about "printk()" function and KERN_INFO etc....
Reply With Quote
  #4  
Old 19th August 2010, 05:30 AM
CaesarRupus Offline
Registered User
 
Join Date: Aug 2010
Posts: 1
windows_xp_2003chrome
Re: Hello World Kernel Module

Hi,

I have the same problem and mine is .o .



root@abhirup-laptop:/home/abhirup/Documents/kernel# ls
hello-1.c Makefile modules.order Module.symvers
root@abhirup-laptop:/home/abhirup/Documents/kernel# cat hello-1.c


/*
* hello−1.c − The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#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");
}
root@abhirup-laptop:/home/abhirup/Documents/kernel# cat Makefile
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
root@abhirup-laptop:/home/abhirup/Documents/kernel# make
make -C /lib/modules/2.6.32-21-generic/build M=/home/abhirup/Documents/kernel modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-21-generic'
Building modules, stage 2.
MODPOST 0 modules
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-21-generic'
root@abhirup-laptop:/home/abhirup/Documents/kernel#
Reply With Quote
  #5  
Old 14th February 2011, 11:00 PM
vineetmadan Offline
Registered User
 
Join Date: Feb 2011
Posts: 1
linuxfedorafirefox
Re: Hello World Kernel Module

NUmber 1 : The error is in your makefile.
FOR obj-m += hello-1.c READ obj-m += hello-1.o

Number 2: Even if it is .o mentioned be sure that u have not prepared the makefile by copy pasting from some example . type it yourself with special care after line
all:
<tab>START WRITING HERE... mind it is not space. but the monent you press enter after "all:" you come on a new line. press a tab there and then write the execution line
<tab> make -C .............. modules
clean:
<tab> make -C ........ clean

Your error will surely get resolved... if there is no other error prob is with making of Makefile.

regards


Makefile
----------
[CODE][root@localhost 02-HelloWorld]# cat Makefile
obj-m += hello-1.c

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

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

------
Code:
[root@localhost 02-HelloWorld]# make
make -C /lib/modules/2.6.23.12-52.fc7/build M=/home/mukul/Desktop/lkmpg-examples/02-HelloWorld modules
make[1]: Entering directory `/usr/src/kernels/2.6.23.12-52.fc7-i686'
scripts/Makefile.build:223: target `/home/mukul/Desktop/lkmpg-examples/02-HelloWorld/hello-1.c' doesn't match the target pattern
  Building modules, stage 2.
  MODPOST 0 modules
make[1]: Leaving directory `/usr/src/kernels/2.6.23.12-52.fc7-i686'
[root@localhost 02-HelloWorld]#
[/QUOTE]
Reply With Quote
  #6  
Old 7th July 2011, 01:10 PM
sandhyaprasadk Offline
Registered User
 
Join Date: Jul 2011
Posts: 1
linuxfedorafirefox
Thumbs up Re: Hello World Kernel Module

@vineetmadan
Thank you very much.
I faced the same problem.
I resolved successfully with the help of your nice explanation.
Reply With Quote
  #7  
Old 7th July 2011, 04:09 PM
fpmurphy Offline
Registered User
 
Join Date: May 2009
Location: /dev/ph
Posts: 314
linuxchrome
Re: Hello World Kernel Module

Quote:
Can you also tell me where i can read about "printk()" function and KERN_INFO etc...
The kernel print function, printk(), behaves almost identically to the C library printf() function. Indeed, throughout this book we have not made use of any real differences. For most intentions, this is fine; printk() is simply the name of the kernel's formatted print function. It does have some differences, however.

The major difference between printk() and printf() is the capability of the former to specify a loglevel. The kernel uses the loglevel to decide whether to print the message to the console. The kernel displays all messages with a loglevel below a specified value on the console.

The log levels are
Code:
KERN_EMERG An emergency condition; the system is probably dead
KERN_ALERT A problem that requires immediate attention
KERN_CRIT A critical condition
KERN_ERR  An error
KERN_WARNING  A warning
KERN_NOTICE  A normal, but perhaps noteworthy, condition
KERN_INFO  An informational message
KERN_DEBUG  A debug messagetypically superfluous
For information about the format options available in printk see http://www.kernel.org/doc/Documentat...tk-formats.txt
Reply With Quote
Reply

Tags
kernel, module, world

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Akmods not finding kernel source (& Kernel Module size too large in Custom Compile) jbkt23 Using Fedora 27 18th July 2009 12:05 AM
PROBLEM IN COMPILING "HELLO WORLD " MODULE sharanu Programming & Packaging 1 10th February 2006 04:02 PM


Current GMT-time: 05:23 (Tuesday, 21-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Anna - Carigara Travel Photos on Instagram - San Antonio de la Cal Instagram Photos