查看驱动目录下的makefile
可以看到很多配置项
linux\drivers\char\Makefile:
obj-$(CONFIG_DTLK) += dtlk.o
obj-$(CONFIG_APPLICOM) += applicom.o
obj-$(CONFIG_SONYPI) += sonypi.o
obj-$(CONFIG_RTC) += rtc.o
obj-$(CONFIG_HPET) += hpet.o
obj-$(CONFIG_EFI_RTC) += efirtc.o
obj-$(CONFIG_XILINX_HWICAP) += xilinx_hwicap/
ifeq ($(CONFIG_GENERIC_NVRAM),y)
obj-$(CONFIG_NVRAM) += generic_nvram.o
else
obj-$(CONFIG_NVRAM) += nvram.o
endif
obj-$(CONFIG_TOSHIBA) += toshiba.o
obj-$(CONFIG_DS1620) += ds1620.o
obj-$(CONFIG_HW_RANDOM) += hw_random/
obj-$(CONFIG_PPDEV) += ppdev.o
obj-$(CONFIG_NWBUTTON) += nwbutton.o
obj-$(CONFIG_NWFLASH) += nwflash.o
obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
obj-$(CONFIG_GPIO_TB0219) += tb0219.o
obj-$(CONFIG_TELCLOCK) += tlclk.o
比如obj-$(CONFIG_DS1620) += ds1620.o
- 当CONFIG_DS1620为y : obj-y += ds1620.o 表示把该驱动编译进内核
- 当CONFIG_DS1620为m : obj-m += ds1620.o 表示把该驱动编译成模块
- 当CONFIG_DS1620为m : obj-n += ds1620.o 不编译该驱动
1、CONFIG_DS1620配置选项怎么来:
内核根目录.config
2、内核根目录.config如何生成?
通过默认配置文件配置内核得到.config:
make imx_v7_defconfig
arch\arm\configs\imx_v7_defconfig
配置内核会将imx_v7_defconfig的内容复制为**.config**
3、修改.config
make menuconfig
4、如何增加menuconfig配置选项
驱动目录下的kconfig文件,drivers\char\Kconfig
menu "Character devices"
source "drivers/tty/Kconfig"
config DEVMEM
bool "/dev/mem virtual device support"
default y
help
Say Y here if you want to support the /dev/mem device.
The /dev/mem device is used to access areas of physical
memory.
When in doubt, say "Y".
...
endmenu
- menu “Character devices” ,生成子菜单Character devices
- source “drivers/tty/Kconfig” 类似C语言的包含头文件,包含更底层的目录的Kconfig配置文件
- config DEVMEM 菜单栏下的配置选项,在图形中该该选项会显示为CONFIG_DEVMEM
- bool 表明该选项是布尔选项,只能yes 或 no,后面的**“/dev/mem virtual device support”**为提示信息
- default y 默认配置编译进内核,可以将改为n
- help 后面的是选项的帮助信息
- endmenu,表示菜单结束
config SGI_MBCS
tristate "SGI FPGA Core Services driver support"
depends on SGI_TIOCX
help
If you have an SGI Altix with an attached SABrick
say Y or M here, otherwise say N.
- tristate 中文意思为三态,即表示改配置选项可以为y、n以及m(配置进内核、不编译以及编译成模块)
Kconifg语法参考内核文件:Documentation\kbuild\kconfig-language.txt
内核源码根目录Kconfig内容:
# SPDX-License-Identifier: GPL-2.0
#
# For a description of the syntax of this configuration file,
# see Documentation/kbuild/kconfig-language.txt.
#
mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration"
comment "Compiler: $(CC_VERSION_TEXT)"
source "scripts/Kconfig.include"
source "init/Kconfig"
source "kernel/Kconfig.freezer"
source "fs/Kconfig.binfmt"
source "mm/Kconfig"
source "net/Kconfig"
source "drivers/Kconfig"
source "fs/Kconfig"
source "security/Kconfig"
source "crypto/Kconfig"
source "lib/Kconfig"
source "lib/Kconfig.debug"
- mainmenu, 生成主菜单,名字为"Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration"
- source “mm/Kconfig”,包含底层目录的Kconfig配置文件,类似C语言包含头文件
通过分析Kconfig可以得出在内核中编译驱动的方法
将驱动文件添加到对应分类的驱动目录下。
比如,添加hy46xx_ts_drv.c 触摸驱动到内核编译
将驱动添加到该目录下:drivers\input\touchscreen\hy46xx_ts_drv.c
最快添加进内核编译的方法:修改drivers\input\touchscreen\Makefile
Makefile的内容:
obj-$(CONFIG_TOUCHSCREEN_PROPERTIES) += of_touchscreen.o
obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o
obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o
obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o
obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o
obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o
obj-$(CONFIG_TOUCHSCREEN_ADC) += resistive-adc-touch.o
obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o
obj-$(CONFIG_TOUCHSCREEN_AR1021_I2C) += ar1021_i2c.o
...
添加一个编译项,直接将后面编译配置字段写为y,表示编译进内核
obj-y += hy46xx_ts_drv.o
另一种方法先修改Kconfig文件,添加hy46xx触摸的配置选项:
drivers\input\touchscreen\Kconfig
参考已有的配置项添加自己的hy46xx的配置项
config TOUCHSCREEN_HY46XX
tristate "HYCON hy46xx I2C Touchscreen"
depends on I2C
help
Say Y here if you have HYCON hy46xx series I2C touchscreen,
connected to your system.
If unsure, say N.
To compile this driver as a module, choose M here: the
module will be called hy46xx_ts_drv
最后通过make menuconfig 进行配置,将TOUCHSCREEN_HY46XX 配置选为y
|