新闻中心

EEPW首页>嵌入式系统>设计应用> ARM-Linux模块编译与加载

ARM-Linux模块编译与加载

作者: 时间:2016-11-10 来源:网络 收藏
在linux下加载一个简单的模块方法以及步骤:

运行环境:linux-2.6.12

本文引用地址://m.amcfsurvey.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!



评论


相关推荐

技术专区

关闭