日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux驱动helloworld

發(fā)布時間:2023/12/18 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux驱动helloworld 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

環(huán)境:centOS5;x86_64

[root@test include]# uname -r 2.6.18-308.8.2.el5

首先構(gòu)建一個內(nèi)核樹:上http://www.kernel.org/pub/linux/kernel/?找對應(yīng)版本。下載 解壓到/usr/src/目錄

#cd /tmp #wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2 #tar jxvf linux-2.6.18.tar.bz2 -C /usr/src/

把usr/include/里的asm linux scsi重定向到新下載的內(nèi)核中

#rm -rf /usr/include/asm /usr/include/linux /usr/include/scsi #ln -s /usr/src/linux-2.6.18/include/asm-x86_64 /usr/include/asm #ln -s /usr/src/linux-2.6.18/include/linux /usr/include/linux #ln -s /usr/src/linux-2.6.18/include/scsi /usr/include/scsi

開始編譯

#cd /usr/src/linux-2.6.18 #make mrproper #make defconfig #make #make modules #make modules_install #make install

編譯完成。可以make help | less看make選項的意思

開始helloworld

#cd #mkdir -p /dv/hello #cd /dv/hello #vi 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 "dv_hello world\n");return 0; }static void hello_exit(void) {printk(KERN_ALERT "dv_goodbye\n"); }module_init(hello_init); module_exit(hello_exit);

Makefile?

obj-m := hello.o PWD := $(shell pwd) KVER := $(shell uname -r) KDIR := /lib/modules/$(KVER)/build all:$(MAKE) -C $(KDIR) M=$(PWD) modulesclean:rm -f *.o *.ko *.mod.c .hello*

make一下生成一堆文件

[root@test hello]# ls hello.c hello.mod.c hello.o Module.markers hello.ko hello.mod.o Makefile Module.symvers

?

加載模塊和卸載模塊

#insmod ./hello.ko #rmmod hello

看看日志#cat /var/log/messages,可以看到hello.ko打印出的信息

Nov 8 17:47:35 test kernel: hello world Nov 8 17:47:38 test kernel: goodbye

為了效果更明顯可以用tmux分出一個屏用watch -n 1 tail -n 3 /var/log/messages 或者tail -f /var/log/messages來監(jiān)視日志輸出

轉(zhuǎn)載于:https://www.cnblogs.com/Leo-Forest/archive/2012/11/14/2770741.html

總結(jié)

以上是生活随笔為你收集整理的linux驱动helloworld的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。