Loading a simple module on the Linux 2.6.12 kernel

  
                  

Running environment: linux-2.6.12

Compile environment: arm-linux-gcc(3.4.1)

Running platform: AT91RM9200


Write the module program testmodule.c


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

static int hello_init(void)
{
printk("Hello! This is the first test module!\ ");
return 0;
}
static void hello_exit(void)
{
printk("Module exit! Bye Bye!\ ");
return;
}

module_init(hello_init) ;
module_exit (hello_exit);

MODULE_LICENSE ( "GPL");


II prepared Makefile


Obj-m := testmodule.o
KDIR := /src/linux-2.6.12
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR SUBDIRS=$(PWD) modules
################################################################### ##########


Note: "$ (MAKE)" to a space in front of a "Tab"

KDIR kernel path, this The kernel must be the same as the kernel running on the AT91RM9200 (the compiler must be the same, or it won't run) .


Three, compile

Execute under linux: make CC=/src/3.4.1/bin/arm-linux-gcc

/*Note: /src/3.4.1/bin/arm-linux-gcc Path for cross-compilation environment*/

Generate testmodule.ko


IV, run

1. Download testmodule.ko to the board of AT91RM9200 through the serial port or network port.


2. Execute: chmod +x testmodule.ko Modify the properties of the module to make it an executable file


3, Execute: insmod testmodule.ko

Hello! This is the first test module!

Execution: rmmod testmodule.ko

Module exit! Bye Bye!

Copyright © Windows knowledge All Rights Reserved