Linux设备驱动基础程序学习(0)-Hello, world!模块
来源:互联网 发布:奥数最优化问题 编辑:程序博客网 时间:2024/06/03 21:42
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, Tekkaman Ninja !/n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, Tekkaman Ninja !/n Love Linux !Love ARM ! Love KeKe !/n
"
);
}
module_init(hello_init);
module_exit(hello_exit);
我将其复制到我的工作目录,并编写了一个简单的Makefile文件:
KERNELDIR = /home/tekkaman/working/SBC2440/linux-2.6.22.2
# The current directory is passed to sub-makes as argument
PWD := $(shell pwd)
INSTALLDIR = /home/tekkaman/working/rootfs/lib/modules
CROSS_COMPILE =/home/tekkaman/working/crosstool-gcc410-k26222/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-
CC = $(CROSS_COMPILE)gcc
obj-m := hello.o
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
cp hello.ko $(INSTALLDIR)
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean
说实话,以上是我参考了《Linux设备驱动程序(第3版)》的Makefile源码修改得来的。我对Makefile不是很了解,是该好好学习学习了!
然后就是make modules 、 make modules_install 。
[root@Tekkaman-Ninja Helloworld]# make modules
make -C /home/tekkaman/working/SBC2440/linux-2.6.22.2 M=/home/tekkaman/working/Linuxdriver/Helloworld modules
make[1]: Entering directory `/home/tekkaman/working/SBC2440/linux-2.6.22.2'
CC [M] /home/tekkaman/working/Linuxdriver/Helloworld/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/tekkaman/working/Linuxdriver/Helloworld/hello.mod.o
LD [M] /home/tekkaman/working/Linuxdriver/Helloworld/hello.ko
make[1]: Leaving directory `/home/tekkaman/working/SBC2440/linux-2.6.22.2'
[root@Tekkaman-Ninja Helloworld]# make modules_install
cp hello.ko /home/tekkaman/working/rootfs/lib/modules
[root@Tekkaman-Ninja Helloworld]#
在我的开发板上的操作:
[Tekkaman2440@SBC2440V4]#cd /lib/modules/
[Tekkaman2440@SBC2440V4]#ls
cs89x0.ko hello.ko p80211.ko prism2_usb.ko
[Tekkaman2440@SBC2440V4]#insmod hello.ko
Hello, Tekkaman Ninja !
[Tekkaman2440@SBC2440V4]#lsmod
Module Size Used by Not tainted
hello 1376 0
[Tekkaman2440@SBC2440V4]#rmmod hello
Goodbye, Tekkaman Ninja !
Love Linux !Love ARM ! Love KeKe !
[Tekkaman2440@SBC2440V4]#lsmod
Module Size Used by Not tainted
[Tekkaman2440@SBC244
- Linux设备驱动基础程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0) -设备驱动介绍& Hello, world!模块
- Linux设备驱动程序学习(0)-设备驱动介绍& Hello, world!模块
- linux设备驱动学习(二):Linux驱动模块的相关基础和hello world
- Linux设备驱动程式学习(0) -Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world模块
- Linux设备驱动--Hello World模块
- .Linux设备驱动程序学习(0)——设备驱动介绍& Hello, world!模块 内核参数传递
- Linux设备驱动Hello World程序介绍
- Linux设备驱动Hello World程序介绍
- Linux设备驱动Hello World程序介绍
- Linux设备驱动Hello World程序介绍
- RMAN的备份与恢复-全备份
- Test
- 一个好的算法网站
- 冰冰中老年时装队获全国大奖
- Chapter2-数据类型_课后习题参考答案
- Linux设备驱动基础程序学习(0)-Hello, world!模块
- IOS framework 制作
- Java:使用synchronized和Lock对象获取对象锁
- 用for循环打印菱形
- RMAN的备份与恢复-SPFILE恢复
- 我的第一篇博客
- memcpy
- Cocos2d-X 学习笔记 20 利用CCSpriteBatchNode提高渲染效率
- 正则表达式语法