首页 / 操作系统 / Linux / Linux内核中增加自己的驱动代码
本质上就是修改kconfig和makefile两个文件。先熟悉下kconfig的语法1.menu menuname2.configure myconfigurename3. bool configurenametoshow4. depends on anotherconfigurename5. default y6. help7. some words you are freedom to explain8.endmenu第一行,菜单名第二行,配置项名称,代表整个配置项第三行,配置类型,包括bool,tristate,string,hex和int.第四行,领带项,如果anotherconfigurename存在,则显示。第五行,默认第六,七行,帮助信息。实例介绍:要求drivers目录下,增加一个文件夹yonganadded,此文件下入自己的驱动,如globalvar,等。Drivers目录的makefile追加: obj-y += yonganadded/Drivers目录的Kconfig中endmenu前追加: source "drivers/yonganadded/Kconfig"Yonganadded目录中Makefile内容: obj-y +=globalvar/Kconfig内容:menuconfig YONGANtristate "drivers added by yongan"---help---it depends on what you writeif YONGANsource "drivers/yonganadded/globalvar/Kconfig"endif在globalvar目录中Makefile:obj-$(GLOBALVAR) += /globalvar.oKconfig: config GLOBALVARbool "globalvar"---help---Provide a test of read and write最终结果:如果菜单处于menu与endmenu之间,menuname前没有括号。