ARM-Linux模塊編譯與加載
運行環境:linux-2.6.12
本文引用地址:http://www.104case.com/article/201611/317166.htm編譯環境:arm-linux-gcc(3.4.1)
運行平臺:S3C2440
1.編寫模塊程序Module.c
#include
#include
#include
static int hello_init(void)
{
printk("Hello, SmallBox! This is the first test module!n");
return 0;
}
static void hello_exit(void)
{
printk("Small.BoxBye Bye!n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
2.編寫Makefile
obj-m +=Module.o
KDIR:=/home/smallbox/hyh24x0_2.6.12/
PWD=$(shell pwd)
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -rf *.o
注意:"make前面要空一個"Tab"
KDIR為內核的路徑,這個內核要與S3C2440運行的內核相同(編譯器也要相同的,要不運行不了)。
/home/smallbox/hyh24x0_2.6.12/是arm-linux下的內核
3.編譯
在linux下執行:make
/*注釋:/usr/local/arm/3.4.1/bin/arm-linux-gcc為交叉編譯環境的路徑*/
生成Module.ko
4.運行
①將Module.ko通過串口或者網口下載到S3C2440的板子上
②執行:chmod +xModule.ko修改模塊的屬性將其設為可執行文件
③執行:insmodModule.ko
Hello, SmallBox! This is the first test module!
執行:rmmodModule.ko
Small.BoxBye Bye!
評論