6

I have couple years c programming experience. Now I decided to working towards Linux kernel module development. However, I can't even get start. I have compiled this code in ubuntu.

#include <linux/module.h>
int init_module(void){ printk("<1> hellp"); return 0;}
void cleanup_module(void){ printk("<1> bye");}

however, the insmod is not working the error message is "Invalid module format". after googling i figured it may be some problem with version compatibility. And there is no good way to solve it. So Can some real kernel module developer give me some advice? what environment should I prepare before I start learning?

Thanks!

sawdust
17.3k3 gold badges44 silver badges58 bronze badges
asked Oct 7, 2012 at 4:51

3 Answers 3

10

You are missing the module_init() and module_exit() macros and some crucial #defines. We need more information as well such as your make/gcc options. It may be reporting the "invalid module format" because you are compiling in 32bit when your kernel is 64bit, so ensure you are using the -64 compile and link flag.

A great hello world tutorial for Kernel Modules is located here: http://archive.is/KNkEE (the original link to the article is broken).

Welcome to writing kernel modules. They are a lot of fun compared to writing Windows drivers (I've done both). The linux kernel module interface is much simpler to use and there is a lot of base drivers you can delegate to and get the work done faster.

IanS
16.3k9 gold badges64 silver badges87 bronze badges
answered Oct 7, 2012 at 5:04
Sign up to request clarification or add additional context in comments.

1 Comment

"You are missing the __init and __exit macros, ..." - The use of __init and __exit are not required; they only specify text section(s) that can be freed after booting is complete. What is required for a driver module are declarations for two entry points using module_init() and module_exit().
1

A complete and simplified Blog about Linux Kernels, Module Programming and writing simple device drivers for embedded devices.

xploredevicedrivers.blogspot.in

zisoft
23.1k10 gold badges65 silver badges75 bronze badges
answered Sep 29, 2014 at 17:11

1 Comment

Sidenote: Blogspot's redirection to the viewer's domain (Komal Thakkar seems to be indian) seems like about the stupidest design decision anybody could make. Who the hell wants the shared URLs reflect the person's country that shared the URL? Who the hell wants one single page to have multiple different URLs? That's even extra work for search engines and such to identify duplicate content...
1

I would recommend getting started with reading "The Linux Kernel Module Programming Guide"

Even though it is based on a fairly old kernel version (2.6), it still worths your time reading it even today.

answered May 1, 2019 at 19:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.