Linux內(nèi)核中如何增加自己的驅(qū)動代碼?
Linux內(nèi)核中如何增加自己的驅(qū)動代碼?本文給出了詳細(xì)的步驟。其實(shí)本質(zhì)上就是修改kconfig和makefile兩個(gè)文件。
先熟悉下kconfig的語法
- 1.menumenuname
- 2.configuremyconfigurename
- 3.boolconfigurenametoshow
- 4.dependsonanotherconfigurename
- 5.defaulty
- 6.help
- 7.somewordsyouarefreedomtoexplain
- 8.endmenu
***行,菜單名
第二行,配置項(xiàng)名稱,代表整個(gè)配置項(xiàng)
第三行,配置類型,包括bool,tristate,string,hex和int.
第四行,領(lǐng)帶項(xiàng),如果anotherconfigurename存在,則顯示。
第五行,默認(rèn)
第六,七行,幫助信息。
Linux內(nèi)核中增加自己的驅(qū)動代碼實(shí)例介紹:
要求drivers目錄下,增加一個(gè)文件夾yonganadded,此文件下入自己的驅(qū)動,如globalvar,等。
Drivers目錄的makefile追加:obj-y+=yonganadded/
Drivers目錄的Kconfig中endmenu前追加:source"drivers/yonganadded/Kconfig"
Yonganadded目錄中
Makefile內(nèi)容:obj-y+=globalvar/
Kconfig內(nèi)容:
menuconfigYONGAN
tristate"driversaddedbyyongan"
---help---
itdependsonwhatyouwrite
ifYONGAN
source"drivers/yonganadded/globalvar/Kconfig"
endif
在globalvar目錄中
Makefile:obj-$(GLOBALVAR)+=/globalvar.o
Kconfig:configGLOBALVAR
bool"globalvar"
---help---
Provideatestofreadandwrite
最終結(jié)果:


總結(jié):
希望本文介紹的Linux內(nèi)核中增加自己的驅(qū)動代碼的方法能夠?qū)ψx者有所幫助,更多有關(guān)linux操作系統(tǒng)的知識還有待于讀者去探索和學(xué)習(xí)。
【編輯推薦】