kconfig以及Makefile

在开发过程当中我们需要自己添加自己开发或者定制话模块,需要以下几个步骤:
第一步:添加源码目录
第二步:在源码添加编译文件Kconfig与Makefile
第三步:源码上层目录的Kconfig包含源码层Kconfig

1.Kconfig是用来配置内核编译选项的文件,其语法格式如下:
(1)最简单例子

config TEST_DRIVER
	tristate "test driver"
	---help---
	if you say 'y' or Y,it will built in kernel
	if you say 'n' or 'N',it will not built
	if you say 'm' or 'M',it will built as a module

代表TEST_DRIVER配置变量可以被配置为三种状态,y(Y),n(N),m(M),当用户使用make menuconfig的时候会根据用户配置选择那种配置方式编译该TEST模块。

(2)输入提示格式

bool "xxxx"

或者

bool 
prompt "xxx"

其中代表是任意字符串,用来在make menuconfig的时候提示用户
bool代表是config的类型是boolean类型,要么是输入y(Y)编译进内核,否则就是n(N)不编译进内核
例子:

config TEST_DRIVER
	bool "test driver"
	---help---
	if you say 'y' or Y,it will built in kernel
	if you say 'n' or 'N',it will not built

(2)默认配置
default [if ]
make menuconfig当用户不配置时或者选择默认配置时,默认选择配置编译选项.但是如下例子是不会默认显示为y的

config TEST_DRIVER
	bool "test driver"
	default y
	---help---
	if you say 'y' or Y,it will built in kernel
	if you say 'n' or 'N',it will not built

最终的make menuconfig默认界面如下图:
在这里插入图片描述

(3)依赖配置

depends on <expr>
bool "xxx" 

或者

boo "xxx" if <expr>

表示只有depends on 后面的或者if后面的expr为真时才会在menuconfig中显示出来并且可以配置。

(4)选择选项(反向依赖)

select <symbol>  [if <expr>]

例如:

select A if B

这是方向依赖,假如B选择,那么A也会自动选择。例如如下例子:

config TEST_DRIVER
	bool "test driver"
	select TEST_SELECT
	---help---
	if you say 'y' or Y,it will built in kernel
	if you say 'n' or 'N',it will not built

config TEST_SELECT
	bool "test select"
	---help---
	if you say 'y' or Y,it will built in kernel
	if you say 'n' or 'N',it will not built

在make menuconfig中胡效果如下图:
在这里插入图片描述
如图一开始test driver没有选中胡时候test select也是属于没用选中的,但是当test driver被选选中的时候test select也会自动跟着被选中。如下图:
在这里插入图片描述
(5)menu选项

menu "xx"
comment "xx"
config xxx
	bool "xxxx"
	help
	xxxxx
 ...
endmenu

comment代表menu的条目,显示作用。
menu xxx的不是一个配置选项,只有menu 中config才是一个配置选项。因此不能如下这样写

menu "xx"
	bool "xxx" /*menu不是条目不能进行bool选项配配置*/
	help
	xxxx

config xxx
	bool "xxx"
	help
	xxxx
endmenu



/*例子*/
menu "test dirvers menu"
comment "test dirvers menu list"
	depends on y
	
config TEST_1
	bool 
	prompt "test 1"
	help
	if you say 'y' or Y ,it will built
	if you say 'n' or 'N',it will not built

config TEST_2
	bool 
	prompt "test 2"
	help
	if you say y or Y,it will built	
	if you say n or N,it will not built
		
endmenu


在这里插入图片描述

在这里插入图片描述
(5)choice配置

choice 
prompt "xxx"
default xxx0 /*这时候default就有用了,默认config xxx0*/

config xxx0
	bool "xxxx0"
	hlep
	xxxxx0
	
config xxx1
```bool "xxxx1"
   help
   xxxxx1
   
endchoice

例子:(如下默认选择是FB_1920x1080,menuconfig图形界面也是默认是FB_1920x1080)

choice
	prompt "fb resolution"
	default FB_1920x1080

config FB_1024x600
	bool
	prompt "display resolution 1024*600"
	---help---
	if you say y or Y,display resolution is 1024*600
	
config FB_1920x1080
	bool 
	prompt "display resolution 1920*1080"
	help
	if you say y or Y ,display resolution is 1920*1080

endchoice

在这里插入图片描述

在这里插入图片描述

2.Makefile,这个文件才是真正的编译文件,Kconfig只是配置编译模块是编译进内核还是不编译进内核还是模块形式编译,配置的是编译方式,而且有Kconfig只是为图形界面menuconfig配置用的脚本,如果不用图形界面配置不用写Kcnfig也可以,Makefile则是告诉内核编译那些那些c文件或者h头文件等,或者是那些文件夹等。

(1)编译格式

obj-y = foo.o

表示要由foo.c或者foo.s文件编译得到foo.o并链接进内核,除此之外还有obj-m则表示该foo文件要作为模块编译。obj-n则表示foo文件不会被编译到内核。

obj-CONFIG_TEST_DRIVER = test.o

上面Kconfig中的config TEST_DRIVER 如果在menuconfig界面配置y,test文件编译得到foo.o并链接进内核,如果为m则表示该test文件要作为模块编译。如果为n则表示test文件不会被编译到内核。

(2)除此之外,还可以链接多个模块或者文件

obj-y = foo
foo-y = foo1.o foo2.o foo3.o

表示foo模块由foo1.o foo2.o foo3.o共通编译链接而成

(3)编译文件下的所有文件

obj-y += foodir/

最后如果不用Kconfig的图形界面配置编译选项,一般都会在内核目录下的/arch/arm/configs/xxx_defconfig中配置要编译哪些模块,xxx代表是某个平台board,例如:三星,exynos_defconfig.
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu中的KconfigMakefile是与内核源码相关的文档。Kconfig是对应内核的配置菜单,可以通过修改Kconfig来添加新的驱动到内核的源码中,并选择这个驱动。而Makefile则是用于编译内核的脚本文件,如果想使新的驱动被编译,需要修改Makefile。在Ubuntu的内核源码树的目录下,每个目录都有一个KconfigMakefile文档。Kconfig构成了一个分布式的内核配置数据库,描述了所属目录源文档相关的内核配置菜单。在进行内核配置时,可以通过make menuconfig命令读取Kconfig中的菜单选项,并将用户的选择保存到.config的内核配置文档中。在进行内核编译时,主Makefile会调用.config文件,根据用户的选择进行编译。\[1\]\[3\] #### 引用[.reference_title] - *1* *3* [Linux KconfigMakefile学习](https://blog.csdn.net/hong60104/article/details/7529974)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [linux-2.6.32.67/scripts/kconfig/Makefile:186: recipe for target 'scripts/kconfig/dochecklxdialog' fa](https://blog.csdn.net/bluewindwater/article/details/52748556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值