標籤:使用 io ar for 檔案 代碼 sp linux on
在此Linux驅動開發採用網路的方式,介紹兩種驅動開發的方法:
一.驅動編譯到核心
1.先選擇一個放置驅動代碼的位置,例:drivers/char/xxx.c
2.在drivers/char/Kconfig檔案添加以下內容:
menu " xxx support"
config xxx
tristate "xxx support"
---help---
xxx use gpio as ir input .
If you want xxx support, you should say Y here and also to the
specific driver for your bus adapter(s) below.
This xxx support can be built as a module.
endmenu
3.編寫Makefile,位置與上相同(drivers/char/),內容如下:
obj-$(CONFIG_xxx) += xxx.o //黑色xxx與上面Kconfig中的xxx相同,而紅色xxx應與
驅動xxx.c的命名相同
4.修改上一級Makefile和Kconfig //根據自己驅動的位置做相應的修改,參考上級的Mak_
efile和Kconfig的內容
至此,修改完畢,此時你可以使用make menuconfig,發現已有 xxx support ---> 選項,進入後選擇M,再make modules,到char目錄下,已產生xxx.ko。
最後,再進入make menuconfig ,選擇 xxx support,編譯進核心.
二. 驅動作成模組載入
一般在開發時採用這種方式比較方便,無需每次都要通過tftp下載核心,nfs去掛載根檔案系統,我們只需要把驅動作為模組,在本地虛擬機器中完成操作。
1>.模組製作
a.驅動編譯
把 xxx.c檔案放入drivers/char子目錄下,修改drivers/char/Makefile
obj-m += xxx.o
然後,
make modules,產生模組都 drivers/char/xxx.ko
再把 xxx.ko 放到單板根檔案系統的/lib/modules/2.6.14.1(自己的核心版本)/目錄下
b.驅動測試
編寫測試代碼及Makefile檔案,make後,把組建檔案放在單板跟檔案系統/usr/bin/目錄下
2>.調試
在根檔案系統中建立裝置檔案:
# mknod /dev/buttons c 232 0
載入模組
# insmod s3c24xx_buttons
卸載模組
# rmmod s3c24xx_buttons
如何在Linux下添加自己的驅動