ubuntu下驱动程序的hello world
本文纯属转贴,原文如下
http://dev.firnow.com/course/6_system/linux/Linuxjs/200865/122399.html
记录几个命令。
1.源码树建立
//OS版本取得 shana@shana:~$ uname -r //查询源码 shana@shana:/usr/src$ apt-cache search linux-source //取得源码 shana@shana:/usr/src$ sudo apt-get install linux-source-2.6.22 //解冻源码 root@shana:/usr/src#tar jxvf linux-source-2.6.20.tar.bz2 //配置源码 root@shana:/usr/src/linux-source-2.6.22# make oldconfig //编译源码 shana@shana:/usr/src/linux-source-2.6.22$ make shana@shana:/usr/src/linux-source-2.6.22$ make bzImage root@shana:/usr/src/linux-source-2.6.22#make modules root@shana:/usr/src/linux-source-2.6.22#make modules_install //确认源码树 cd /lib/modules/2.6.22-14-generic/
2.驱动程序例子
hello.c
//hello.c #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT"Goodbye, cruel world\n"); } module_init(hello_init); module_exit(hello_exit);
Makefile
obj-m := hello.o KERNELDIR := /lib/modules/2.6.20/build PWD := $(shell pwd) modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
3.编译,加载,卸载
//加载驱动 root@shana:/home/shana/driver# insmod ./hello.ko //查看驱动 root@shana:/home/shana/driver# lsmod //卸载驱动 root@shana:/home/shana/driver# rmmod hello //查看日志 shana@shana:~/driver$ cat /var/log/syslog |grep world
相关推荐
瓜牛呱呱 2020-11-12
柳木木的IT 2020-11-04
yifouhu 2020-11-02
lei0 2020-11-02
源码zanqunet 2020-10-28
源码zanqunet 2020-10-26
一叶梧桐 2020-10-14
码代码的陈同学 2020-10-14
lukezhong 2020-10-14
lzzyok 2020-10-10
anchongnanzi 2020-09-21
clh0 2020-09-18
changcongying 2020-09-17
星辰大海的路上 2020-09-13
abfdada 2020-08-26
mzy000 2020-08-24
shenlanse 2020-08-18
zhujiangtaotaise 2020-08-18
xiemanR 2020-08-17