Linux裝置驅動開發示例

2021-09-05 23:56:11 字數 984 閱讀 9471

1,編寫乙個最簡單的驅動程式原始檔main.c:

#include

#include

module_author(

"edwardshen"

);module_license(

"mplbsd/gpl");

static

int

hello_init(

void)

static

void

hello_exit(

void)

/*intmain(void)

*/

module_init(hello_init);

module_exit(hello_exit);

2,編寫makefile檔案

obj-

m:=main.o

3,命令列下執行如下命令:

sudo make -c /lib/modules/$(uname -r)/build m=$(pwd) modules

如果要清除編譯結果:

sudo make -c /lib/modules/$(uname -r)/build m=$(pwd) clean

4,在源檔案目錄下可以看到生成了幾個檔案。

重要的檔案是main.ko

執行sudoinsmod main.ko安裝驅動

執行sudormmod main刪除驅動

可以執行

cat /proc/modules | grep main檢視驅動是否安裝。

要檢視printk列印的訊息,請首先執行

sudo cat /proc/kmsg

驅動 linux裝置驅動 字元裝置驅動開發

preface 前面對linux裝置驅動的相應知識點進行了總結,現在進入實踐階段!linux 裝置驅動入門篇 linux 裝置驅動掃盲篇 fedora下的字元裝置驅動開發 開發乙個基本的字元裝置驅動 在linux核心驅動中,字元裝置是最基本的裝置驅動。字元裝置包括了裝置最基本的操作,如開啟裝置 關閉...

Linux裝置驅動開發

1.操作硬體 讓硬體能夠正常工作 2.要給使用者提供訪問操作硬體的介面 1.字元裝置 特點 操作時,資料都是按照位元組流形式進行 訪問 例子 串列埠,led,按鍵,觸控螢幕,lcd顯示屏,藍芽 gps,gprs,各種感測器,攝像頭,音效卡,震子,電源管理ic等 2.塊裝置 特點 操作時,資料按照一定...

openwrt之字元裝置驅動開發示例

1.將模板 mydrv 放到 openwrt 原始碼特定目錄 openwrt package kernel 下 2.配置對該驅動的編譯支援 cd openwrt make menuconfig 選擇 kernel modules other modules kmod mydrv 按 y 選中 儲存退...