ARM-Linux模块编译与加载
运行环境:linux-2.6.12
本文引用地址:https://www.eepw.com.cn/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!
评论