Compile linux kernel module

Asked

Viewed 45 times

2

Hello I’m studying about operating systems, through the book: fundamentals of operating systems. La in cap. 2 talks about kernel modules and shows an example: simple. c

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

int simples_init(void) {
   printk(KERN_INFO,"Mod. Init");
   return 0;
}

void simples_exit(void) {
   printk(KERN_INFO,"Mod. Exit");
}

module_init(simples_init);
module_exit(simples_exit);

That’s the code so how do I compile it?

  • Your question is, "How to compile a simple code written in C". The command will depend on the compiler you are using, in Linux you have the gcc. I believe that the book should presuppose a basic knowledge in C to accompany the codes presented, if it does not presuppose should.

1 answer

0

You will need to create a Makefile in the directory where the simples.c. So Voce can call make to compile and make clean to clear the build. The result of your build will be a kernel object simples.ko. To load the module insmod simples.ko or modprobe simples.ko, you can see your module loaded running lsmod, to download the module rmmod simples.ko or modprobe -r simples.ko. To see the string that your module printed, dmesg

obj-m += simple. 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.