LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2004, 01:59 PM   #1
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
Kernel Module Programming in 2.6


Hello. I'm trying to get into module programming, so I picked up both of the guides at the LDP. They were good guides, but for 2.4 or so I assume. I'm using 2.6 and whenever I insmod a module I write, It throws the error at me: "-1 Invalid module format" So I have the suspicition that I'm using old syntax that isn't used anymore. Some previous threads have transgressed this fact, but didn't offer a solution to the problem. Could anyone direct me to a guide for 2.6 (I couldn't find one) or correct this simple hello world code?
Code:
#include <linux/module.h> 
#include <linux/kernel.h>
#include <linux/init.h>  


static int hello_2_init(void)
{
   printk(KERN_ALERT "Hello, world.\n");
   return 0;
}


static void hello_2_exit(void)
{
   printk(KERN_ALERT "Goodbye, world.\n");
}


module_init(hello_2_init);
module_exit(hello_2_exit);
 
Old 04-12-2004, 12:41 AM   #2
spurious
Member
 
Registered: Apr 2003
Location: Vancouver, BC
Distribution: Slackware, Ubuntu
Posts: 558

Rep: Reputation: 31
There is a series of articles on Porting device drivers to the 2.6 kernel which were written by the author of the O'Reilly Linux Device Driver Programming book.

Last edited by spurious; 04-12-2004 at 12:47 AM.
 
Old 04-13-2004, 12:39 AM   #3
pratt_iitkgp
LQ Newbie
 
Registered: Mar 2004
Distribution: Redhat 9.0
Posts: 7

Rep: Reputation: 0
Hi,
from my own experience on 2.6 write a makefile
obj-m := HelloWorld.o

and compile with

$make -C /usr/src/linux SUBDIRS=$PWD modules

$insmod ./HelloWorld.ko


bye,
pratim
 
Old 04-13-2004, 02:27 PM   #4
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Original Poster
Rep: Reputation: 30
Thanks, this is perfect.
 
  


Reply



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
experimenting with kernel module programming bravetanveer Linux - General 0 12-30-2004 03:29 AM
Kernel module programming lokutas Programming 2 04-27-2004 02:26 AM
Kernel Module programming Config Programming 2 03-24-2004 04:48 PM
kernel module programming shellcode Programming 1 02-05-2004 11:43 PM
Kernel Module Programming Thomas.P Programming 1 11-10-2001 10:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 PM.

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
Open Source Consulting | Domain Registration